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

Suisin/fix: make InputPhoneNumber not following any format in default #494

Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/components/Input/base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
{leftPlaceholder}
</Text>
)}
{formatProps ? (
{formatProps?.format ? (
<PatternFormat
{...commonProps}
{...formatProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ exports[`InputPhoneNumber Component should match the snapshot 1`] = `
class="input peer input__align--left input__size--lg"
id="quill-input-1"
inputmode="numeric"
suisin-deriv marked this conversation as resolved.
Show resolved Hide resolved
placeholder="00 0000 0000"
type="text"
placeholder=" "
type="tel"
value=""
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,9 @@ describe("InputPhoneNumber Component", () => {
expect(asFragment()).toMatchSnapshot();
});

it("should render correctly with default props", () => {
const { getByPlaceholderText } = render(
<InputPhoneNumber {...defaultProps} />,
);
const input = getByPlaceholderText("00 0000 0000");
expect(input).toBeInTheDocument();
});

it("should call onValueChange when input value changes", () => {
const { getByPlaceholderText } = render(
<InputPhoneNumber {...defaultProps} />,
);
const input = getByPlaceholderText("00 0000 0000");
const { getByRole } = render(<InputPhoneNumber {...defaultProps} />);
const input = getByRole("textbox");

fireEvent.change(input, { target: { value: "1234567890" } });
expect(defaultProps.onValueChange).toHaveBeenCalledWith("+11234567890");
Expand All @@ -62,14 +52,14 @@ describe("InputPhoneNumber Component", () => {
});

it("should update phone code and input value state", () => {
const { getByText, getByPlaceholderText } = render(
const { getByText, getByRole } = render(
<InputPhoneNumber
{...defaultProps}
shortCode="US"
codeLabel="Code"
/>,
);
const input = getByPlaceholderText("00 0000 0000");
const input = getByRole("textbox");
const dropdownButton = getByText("Code");

fireEvent.click(dropdownButton);
Expand All @@ -85,15 +75,15 @@ describe("InputPhoneNumber Component", () => {
});

it("should render custom props correctly", () => {
const { getByPlaceholderText } = render(
const { getByRole } = render(
<InputPhoneNumber
inputSize="sm"
{...defaultProps}
status="error"
placeholder="Enter your phone number"
/>,
);
const input = getByPlaceholderText("Enter your phone number");
const input = getByRole("textbox");
expect(input).toBeInTheDocument();
});
});
8 changes: 1 addition & 7 deletions lib/components/Input/input-phone-number/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ const InputPhoneNumberContent = forwardRef<
fillAddonBorderColor,
countryCodes,
shortCode,
placeholder = "00 0000 0000",
formatProps = {
format: "## #### ####",
mask: "",
},
jia-deriv marked this conversation as resolved.
Show resolved Hide resolved
onCodeChange,
onValueChange,
showFlags = true,
Expand Down Expand Up @@ -128,13 +123,12 @@ const InputPhoneNumberContent = forwardRef<
<div ref={containerRef} className="quill-phone-input__container">
<Input
type="tel"
inputMode="numeric"
value={inputValue}
placeholder={placeholder}
addOn={codeAddOn}
inputSize={inputSize}
status={status}
variant={variant}
formatProps={formatProps}
onChange={handleInputChange}
isDropdownOpen={isOpen}
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const meta = {
fieldMarker: false,
show_counter: false,
shortCode: "au",
formatProps: {
format: "",
mask: "",
},
fillAddonBorderColor:
"var(--semantic-color-slate-solid-surface-frame-mid)",
countryCodes: dummyList,
Expand Down
Loading