Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/hip-needles-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sumup-oss/circuit-ui": minor
---

Made PhoneNumberInput default flag size responsive to the input size.
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,21 @@ export interface PhoneNumberInputProps
};
}

const DefaultPrefix: ComponentType<{
type DefaultPrefixProps = {
value?: string | number;
className?: string;
}> = ({ value, ...rest }) =>
size?: FieldSize;
};

const DefaultPrefix = ({ value, ...rest }: DefaultPrefixProps) =>
value ? (
<Flag countryCode={value as FlagProps['countryCode']} alt="" {...rest} />
) : null;

const getDefaultPrefix = (size: FieldSize) => (args: DefaultPrefixProps) => (
<DefaultPrefix size={size} {...args} />
);

/**
* Provides a straightforward way for users to type their phone number in an
* accurate, consistent format including the country code and subscriber number.
Expand Down Expand Up @@ -404,6 +411,7 @@ export function PhoneNumberInput({
(({ value: inputValue, ...rest }) => (
<DefaultPrefix
value={getCountry(countryCode.options, inputValue as string)}
size={size}
{...rest}
/>
))
Expand Down Expand Up @@ -434,7 +442,7 @@ export function PhoneNumberInput({
countryCodeRef as RefObject<HTMLSelectElement | null>,
countryCode.ref as ForwardedRef<HTMLSelectElement>,
)}
renderPrefix={countryCode.renderPrefix ?? DefaultPrefix}
renderPrefix={countryCode.renderPrefix ?? getDefaultPrefix(size)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should getDefaultPrefix(size) be memoized so it doesn't end up creating a new reference on every render?

/>
)}
<Input
Expand Down