Skip to content

Commit 17cada7

Browse files
committed
allow for proper placeholder values
1 parent 0ab4b26 commit 17cada7

File tree

2 files changed

+33
-6
lines changed
  • packages/boxel-ui/addon/src/components

2 files changed

+33
-6
lines changed

Diff for: packages/boxel-ui/addon/src/components/input-group/accessories/index.gts

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export const Select: TemplateOnlyComponent<SelectAccessorySignature> =
152152
@onChange={{@onChange}}
153153
@onBlur={{@onBlur}}
154154
@matchTriggerWidth={{@matchTriggerWidth}}
155+
@selectedItemComponent={{@selectedItemComponent}}
155156
data-test-boxel-input-group-select-accessory-trigger
156157
...attributes
157158
as |item|

Diff for: packages/boxel-ui/addon/src/components/phone-input/index.gts

+32-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
// @ts-ignore
1313
import examples from 'libphonenumber-js/mobile/examples';
1414
import { countries, type TCountryCode, getEmojiFlag } from 'countries-list';
15+
import type { Select } from 'ember-power-select/components/power-select';
1516

1617
interface Signature {
1718
Args: {};
@@ -55,9 +56,9 @@ const getCountryInfo = (countryCode: CountryCode): CountryInfo | undefined => {
5556

5657
export class PhoneInput extends Component<Signature> {
5758
@tracked items: Array<CountryInfo> = [];
58-
@tracked selectedItem: CountryInfo | null = null;
59+
@tracked selectedItem: CountryInfo = getCountryInfo('US')!;
5960

60-
@action onSelectItem(item: CountryInfo | null): void {
61+
@action onSelectItem(item: CountryInfo): void {
6162
this.selectedItem = item;
6263
}
6364

@@ -72,20 +73,24 @@ export class PhoneInput extends Component<Signature> {
7273

7374
get placeholder(): string | undefined {
7475
if (this.selectedItem) {
75-
return `+${this.selectedItem.callingCode} ${this.selectedItem.example?.nationalNumber}`;
76+
return this.selectedItem.example?.nationalNumber;
7677
}
77-
return 'Select a country';
78+
return undefined;
7879
}
7980

8081
<template>
8182
<BoxelInputGroup @placeholder={{this.placeholder}}>
8283
<:before as |Accessories|>
8384
<Accessories.Select
84-
@placeholder='Select a country'
85+
@placeholder={{this.placeholder}}
8586
@selected={{this.selectedItem}}
8687
@onChange={{this.onSelectItem}}
8788
@options={{this.items}}
88-
aria-label='Select an item'
89+
@selectedItemComponent={{PhoneSelectedItem}}
90+
@searchEnabled={{true}}
91+
@searchField='name'
92+
@matchTriggerWidth={{false}}
93+
aria-label='Select an country calling code'
8994
as |item|
9095
>
9196
<div>{{item.flag}} {{item.name}} +{{item.callingCode}}</div>
@@ -94,3 +99,24 @@ export class PhoneInput extends Component<Signature> {
9499
</BoxelInputGroup>
95100
</template>
96101
}
102+
103+
export interface SelectedItemSignature<ItemT> {
104+
Args: {
105+
option: any;
106+
select: Select & {
107+
actions: {
108+
remove: (item: ItemT) => void;
109+
};
110+
};
111+
};
112+
Blocks: {
113+
default: [ItemT, Select];
114+
};
115+
Element: HTMLDivElement;
116+
}
117+
118+
class PhoneSelectedItem<ItemT> extends Component<SelectedItemSignature<ItemT>> {
119+
<template>
120+
<div>{{@option.flag}} +{{@option.callingCode}}</div>
121+
</template>
122+
}

0 commit comments

Comments
 (0)