Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(phone-number): add autoPlaceholder input property #3330

Open
wants to merge 2 commits into
base: rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
luInputStandalone
class="textField-input-value"
[attr.autocomplete]="autocomplete ? autocomplete === 'off' ? 'off' : 'tel-national' : null"
[placeholder]="placeholder()"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { LuDisplayerDirective, LuOptionDirective } from '@lucca-front/ng/core-se
import { FormFieldComponent, InputDirective } from '@lucca-front/ng/form-field';
import { TextInputComponent } from '@lucca-front/ng/forms';
import { LuSimpleSelectInputComponent } from '@lucca-front/ng/simple-select';
import { type CountryCallingCode, formatIncompletePhoneNumber, getCountries, getCountryCallingCode, parsePhoneNumber } from 'libphonenumber-js';
import { type CountryCallingCode, formatIncompletePhoneNumber, getCountries, getCountryCallingCode, parsePhoneNumber, getExampleNumber } from 'libphonenumber-js';
import examples from 'libphonenumber-js/mobile/examples';
import { CountryCode, E164Number } from './types';
import { PhoneNumberValidators } from './validators';

Expand Down Expand Up @@ -67,6 +68,8 @@ export class PhoneNumberInputComponent implements ControlValueAccessor, Validato

@Input() autocomplete?: 'off' | 'tel';

autoPlaceholder = input<boolean>(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of booleans with default value set to true, maybe we should use some kind of disable... input instead?


#onChange?: (value: E164Number) => void;

#onTouched?: () => void;
Expand Down Expand Up @@ -116,6 +119,11 @@ export class PhoneNumberInputComponent implements ControlValueAccessor, Validato

countryCode = computed(() => this.countryCodeSelected() ?? this.defaultCountryCode());

placeholder = computed(() => {
const exampleNumber = this.autoPlaceholder() !== false ? getExampleNumber(this.countryCode(), examples) : undefined;
return exampleNumber?.formatNational() ?? '';
});

displayedNumber = signal<string | undefined>(undefined);

prefixEntry = computed(() => this.#prefixEntries().find((p) => p.country === this.countryCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ export const Basic: StoryObj<PhoneNumberInputComponent & FormFieldComponent & {
errorInlineMessage: 'Invalid Phone Number',
inlineMessageState: 'default',
disabled: false,
autoPlaceholder: true,
},
};