Skip to content

Commit

Permalink
fix(select.tsx/badge.tsx): With icon classes preference (#877)
Browse files Browse the repository at this point in the history
* fix(select.tsx): set correct theme className ordering in twMerge

the ordering of the classNames in the twMerge was removing important classes when Select hadan Icon

fix #869

* fix(badge.tsx): set correct theme className ordering in twMerge

the ordering of the classNames in the twMerge was preventing yo customize padding attributes of the
badge when it had an icon
  • Loading branch information
nigellima authored Jul 25, 2023
1 parent 7e7a101 commit ebe605e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
options: Object.keys(theme.badge.root.color),
control: { type: 'inline-radio' },
},
size: {
options: Object.keys(theme.badge.root.size),
control: { type: 'inline-radio' },
},
},
} as Meta;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const Badge: FC<BadgeProps> = ({
className={twMerge(
theme.root.base,
theme.root.color[color],
theme.icon[Icon ? 'on' : 'off'],
theme.root.size[size],
theme.icon[Icon ? 'on' : 'off'],
className,
)}
data-testid="flowbite-badge"
Expand Down
15 changes: 15 additions & 0 deletions src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, Story } from '@storybook/react';
import { BsFlagFill } from 'react-icons/bs';
import type { SelectProps } from './Select';
import { Select } from './Select';

Expand All @@ -22,3 +23,17 @@ DefaultSelect.args = {
</>
),
};

export const WithIcon = Template.bind({});
WithIcon.args = {
id: 'countries',
icon: BsFlagFill,
children: (
<>
<option>United States</option>
<option>Canada</option>
<option>France</option>
<option>Germany</option>
</>
),
};
2 changes: 1 addition & 1 deletion src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
className={twMerge(
theme.field.select.base,
theme.field.select.colors[color],
theme.field.select.sizes[sizing],
theme.field.select.withIcon[Icon ? 'on' : 'off'],
theme.field.select.withAddon[addon ? 'on' : 'off'],
theme.field.select.withShadow[shadow ? 'on' : 'off'],
theme.field.select.sizes[sizing],
)}
{...props}
ref={ref}
Expand Down

1 comment on commit ebe605e

@vercel
Copy link

@vercel vercel bot commented on ebe605e Jul 25, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.