Skip to content

Commit

Permalink
feat(phoneNumber): add prop customValidityMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Nov 28, 2024
1 parent 54adf95 commit 7644779
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class OdsPhoneNumber {
@Prop({ reflect: true }) public ariaLabel: HTMLElement['ariaLabel'] = null;
@Prop({ reflect: true }) public ariaLabelledby?: string;
@Prop({ reflect: true }) public countries?: OdsPhoneNumberCountryIsoCode[] | OdsPhoneNumberCountryPreset | string;
@Prop({ reflect: true }) public customValidityMessage: string = 'Phone number is incorrect';
@Prop({ reflect: true }) public defaultValue?: string;
@Prop({ mutable: true, reflect: true }) public hasError: boolean = false;
@Prop({ reflect: true }) public isClearable: boolean = false;
Expand Down Expand Up @@ -180,8 +181,7 @@ export class OdsPhoneNumber {
this.value = event.detail.value as string ?? null;

if (!isValidPhoneNumber(this.value, this.isoCode, this.phoneUtils)) {
// TODO add Prop to customize message
await this.inputElement?.setCustomValidity('Phone number format KO');
await this.inputElement?.setCustomValidity(this.customValidityMessage);
} else {
await this.inputElement?.setCustomValidity('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ describe('ods-phone-number rendering', () => {
});
});

describe('customValidityMessage', () => {
it('should be reflected', async() => {
const dummyValue = 'dummy value';

await setup(`<ods-phone-number custom-validity-message="${dummyValue}"></ods-phone-number>`);

expect(root?.getAttribute('custom-validity-message')).toBe(dummyValue);
});

it('should render with expected default value', async() => {
await setup('<ods-phone-number></ods-phone-number>');

expect(root?.getAttribute('custom-validity-message')).toBe('Phone number is incorrect');
});
});

describe('defaultValue', () => {
it('should be reflected', async() => {
const dummyValue = 'dummy value';
Expand Down

0 comments on commit 7644779

Please sign in to comment.