Skip to content

Commit 4800294

Browse files
authored
Add support for max length on telephonenumber input (#164)
This pr aims to add support for max length on telephonenumber input
1 parent deb86a8 commit 4800294

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- support for max length in `TelephoneNumberInput`.
13+
1014
## [4.0.0] - 2026-02-24
1115

1216
### Changed

cypress/cypress/component/TelephoneNumberInput/TelephoneNumberInput.cy.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,27 @@ it("pinning contries works", () => {
8888
cy.get(`.MuiAutocomplete-listbox`).children().eq(1).should("contain", "+39");
8989
cy.get(`.MuiAutocomplete-listbox`).children().eq(2).should("contain", "──");
9090
});
91+
92+
it("setting a max lenght works", () => {
93+
const phoneNumber = faker.phone.number("79#######");
94+
const name = faker.random.alpha(10);
95+
96+
mount(
97+
<div className="p-4">
98+
<Form onSubmit={() => true}>
99+
<TelephoneNumberInput
100+
name={name}
101+
useBootstrapStyle
102+
label="Phone Number"
103+
defaultCountry="CH"
104+
pinnedCountries={["GB", "IT"]}
105+
maxLength={phoneNumber.length}
106+
/>
107+
</Form>
108+
</div>,
109+
);
110+
111+
cy.get(`.MuiInputBase-input`).clear();
112+
cy.get(`.MuiInputBase-input`).type(`${phoneNumber} 1`);
113+
cy.get(`.MuiInputBase-input`).should("have.value", phoneNumber);
114+
});

src/lib/TelephoneNumberInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RegionCode } from "google-libphonenumber";
88

99
interface TelephoneNumberInputProps<T extends FieldValues> extends Omit<
1010
CommonInputProps<T>,
11-
"minLength" | "maxLength" | "addonLeft" | "addonRight" | "name" | "onChange" | "onBlur"
11+
"minLength" | "addonLeft" | "addonRight" | "name" | "onChange" | "onBlur"
1212
> {
1313
useBootstrapStyle?: boolean;
1414
name: FieldPathByValue<T, string | undefined>;

src/lib/components/TelephoneNumberInput/TelephoneNumberInputInternal.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const TelephoneNumberInputInternal = <T extends FieldValues>(props: TelephoneNum
3030
useBootstrapStyle = false,
3131
hideValidationMessage,
3232
placeholder,
33+
maxLength,
3334
} = props;
3435
const {
3536
control,
@@ -118,6 +119,9 @@ const TelephoneNumberInputInternal = <T extends FieldValues>(props: TelephoneNum
118119
field.onBlur();
119120
}}
120121
slotProps={{
122+
htmlInput: {
123+
maxLength,
124+
},
121125
input: {
122126
inputMode: "tel",
123127
startAdornment: <TelephoneNumberInputAdornment disabled={isDisabled} country={country} popupState={popupState} />,

0 commit comments

Comments
 (0)