-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(input-component): support icons left/right #5407
base: main
Are you sure you want to change the base?
Conversation
@IndyVC is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
Can we have this merged? pls |
@shadcn tagging you since I have no idea how this can get ever into shadcn with +- 700 prs 😅 |
({ children, className, ...props }, ref) => { | ||
const Icons = useComposition(children, InputIcon.displayName) | ||
|
||
if (Icons.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve noticed one issue with composition. For my use case and most of the time when building other input components I’ve been playing with the padding-x
property only on the side where the icon is added. This way, there’s no extra space on both sides from only one icon being present.
Something like this is what I thought could do the job:
...
const Icons = useComposition(children, InputIcon.displayName);
if (Icons.length > 0) {
// Since we're sure that the children are InputIcon components, we can cast them to the correct type
// to access the `side` prop
type IconElement = React.ReactElement<InputIconProps>;
const hasRightIcon = Icons.some(
(icon) => (icon as IconElement).props.side === 'right',
);
const hasLeftIcon = Icons.some(
(icon) =>
(icon as IconElement).props.side === 'left' ||
(icon as IconElement).props.side === undefined,
);
// conditionally check for composition (maybe add more variants such as left, right, true, false)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florinkrasniqi I don't fully understand the comment:
do you mean I should be using px-3
instead of left-3
for example? (see iconVariants
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for any confusion. The whole idea is to not have input padding on both sides if only one icon is present but instead only on the icon side.
1581369
to
ed32659
Compare
Using Icons inside an input field is something very common. Unfortunately, shadcn didn't truly provide it out of the box, while it easily could. This PR could solve it.
Following these issues:
I've also extended docs:
And code example: