Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(ui-patterns): multi select cropped caret + extra padding (#50323)

Anthony Lio222127b5c2b2
diff --git a/packages/ui-patterns/src/multi-select/multi-select.test.tsx b/packages/ui-patterns/src/multi-select/multi-select.test.tsx
index 9c50c5284b4..4df62c599a9 100644
--- a/packages/ui-patterns/src/multi-select/multi-select.test.tsx
+++ b/packages/ui-patterns/src/multi-select/multi-select.test.tsx
@@ -56,21 +56,18 @@ describe('multi-select', () => {
)
const trigger = screen.getByRole('combobox')
- expect(trigger).toHaveClass('h-[26px]', 'p-0.5')
- expect(trigger.firstElementChild).toHaveClass('gap-0.5')
+ expect(screen.getByText('Apple')).toBeInTheDocument()
expect(trigger.querySelector('.lucide-chevron-down')).toHaveAttribute('aria-hidden', 'true')
})
- it('keeps the default trigger height stable when the first value is selected', () => {
+ it('swaps the label for a badge when the first value is selected', () => {
const { rerender } = render(
<MultiSelector values={[]} onValuesChange={() => undefined}>
<MultiSelectorTrigger label="Select fruits" />
</MultiSelector>
)
- const trigger = screen.getByRole('combobox')
- expect(trigger).toHaveClass('min-h-[34px]', 'py-1.5')
- expect(screen.getByText('Select fruits')).toHaveClass('leading-5')
+ expect(screen.getByText('Select fruits')).toBeInTheDocument()
rerender(
<MultiSelector values={['Apple']} onValuesChange={() => undefined}>
@@ -78,11 +75,7 @@ describe('multi-select', () => {
</MultiSelector>
)
- expect(screen.getByText('Apple').closest('[class*=rounded]')).toHaveClass(
- 'text-xs/none',
- 'py-[3px]'
- )
- expect(trigger).toHaveClass('min-h-[34px]', 'py-1.5')
+ expect(screen.getByText('Apple')).toBeInTheDocument()
})
it('renders selected values with a custom label', () => {
diff --git a/packages/ui-patterns/src/multi-select/multi-select.tsx b/packages/ui-patterns/src/multi-select/multi-select.tsx
index df0bd27b5e7..41fd9a82dff 100644
--- a/packages/ui-patterns/src/multi-select/multi-select.tsx
+++ b/packages/ui-patterns/src/multi-select/multi-select.tsx
@@ -17,6 +17,7 @@ import {
PopoverAnchor,
PopoverContent,
PopoverContentProps,
+ SIZE,
SIZE_VARIANTS,
SIZE_VARIANTS_DEFAULT,
} from 'ui'
@@ -232,14 +233,16 @@ export interface MultiSelectorTriggerProps extends React.HTMLAttributes<HTMLButt
// The tiny control has no vertical padding to spare, so its children stretch to the
// control height and drop their line-height; the larger sizes center normally.
+const asMinHeight = (height: string) => height.replace('h-', 'min-h-')
+
const MultiSelectorTriggerVariants = cva('', {
variants: {
size: {
- tiny: 'h-[26px] p-0.5 text-xs items-stretch',
- small: 'min-h-[34px] px-3 py-1.5 text-sm items-center',
- medium: 'min-h-[38px] px-4 py-2 text-sm items-center',
- large: 'min-h-[42px] px-4 py-2 text-base items-center',
- xlarge: 'min-h-[50px] px-6 py-3 text-base items-center',
+ tiny: `${SIZE.text.tiny} ${SIZE.height.tiny} p-0.5 items-stretch`,
+ small: `${SIZE.text.small} ${asMinHeight(SIZE.height.small)} p-1.5 items-center`,
+ medium: `${SIZE.text.medium} ${asMinHeight(SIZE.height.medium)} ${SIZE.padding.medium} items-center`,
+ large: `${SIZE.text.large} ${asMinHeight(SIZE.height.large)} ${SIZE.padding.large} items-center`,
+ xlarge: `${SIZE.text.xlarge} ${asMinHeight(SIZE.height.xlarge)} ${SIZE.padding.xlarge} items-center`,
},
},
defaultVariants: {
@@ -251,10 +254,10 @@ const MultiSelectorBadgesVariants = cva('flex overflow-hidden flex-1 min-w-0', {
variants: {
size: {
tiny: 'h-full min-h-0 items-center gap-0.5',
- small: 'gap-1 -ml-1',
- medium: 'gap-1 -ml-1',
- large: 'gap-1 -ml-1',
- xlarge: 'gap-1 -ml-1',
+ small: 'gap-1',
+ medium: 'gap-1',
+ large: 'gap-1',
+ xlarge: 'gap-1',
},
},
defaultVariants: {
@@ -286,10 +289,10 @@ const MultiSelectorLabelVariants = cva(
variants: {
size: {
tiny: 'leading-none',
- small: 'ml-1 leading-5',
- medium: 'ml-1 leading-5',
- large: 'ml-1 leading-5',
- xlarge: 'ml-1 leading-5',
+ small: 'leading-5',
+ medium: 'leading-5',
+ large: 'leading-5',
+ xlarge: 'leading-5',
},
},
defaultVariants: {
@@ -298,35 +301,25 @@ const MultiSelectorLabelVariants = cva(
}
)
-const MultiSelectorInlineInputWrapperVariants = cva('px-0 flex-1 border-none truncate min-w-0', {
- variants: {
- size: {
- tiny: 'h-full',
- small: '',
- medium: '',
- large: '',
- xlarge: '',
+const MultiSelectorInlineInputWrapperVariants = cva(
+ '-ml-1 px-0 flex-1 border-none truncate min-w-0',
+ {
+ variants: {
+ size: {
+ tiny: 'h-full',
+ small: '',
+ medium: '',
+ large: '',
+ xlarge: '',
+ },
},
- },
- defaultVariants: {
- size: SIZE_VARIANTS_DEFAULT,
- },
-})
-
-const MultiSelectorInlineInputVariants = cva('py-0 truncate', {
- variants: {
- size: {
- tiny: 'px-0',
- small: 'px-1',
- medium: 'px-1',
- large: 'px-1',
- xlarge: 'px-1',
+ defaultVariants: {
+ size: SIZE_VARIANTS_DEFAULT,
},
- },
- defaultVariants: {
- size: SIZE_VARIANTS_DEFAULT,
- },
-})
+ }
+)
+
+const INLINE_INPUT_CLASSES = 'py-0 px-1 truncate'
const MultiSelectorTrigger = React.forwardRef<HTMLButtonElement, MultiSelectorTriggerProps>(
(
@@ -411,7 +404,7 @@ const MultiSelectorTrigger = React.forwardRef<HTMLButtonElement, MultiSelectorTr
type="button"
role="combobox"
className={cn(
- 'flex w-full min-w-[200px] justify-between rounded-md border',
+ 'flex w-full min-w-50 justify-between rounded-md border',
'border-strong',
// Empty: raised plate. Filled: sunk well for chips.
values.length > 0 ? 'bg-field' : 'bg-control-raised',
@@ -435,7 +428,13 @@ const MultiSelectorTrigger = React.forwardRef<HTMLButtonElement, MultiSelectorTr
)}
>
{visibleBadges.map((value) => (
- <Badge key={value} className={badgeClasses}>
+ <Badge
+ key={value}
+ className={cn(
+ badgeClasses,
+ deletableBadge && (size === 'tiny' ? 'pr-px' : 'pr-0.5')
+ )}
+ >
{renderValue?.(value) ?? value}
{deletableBadge && (
<div
@@ -446,7 +445,7 @@ const MultiSelectorTrigger = React.forwardRef<HTMLButtonElement, MultiSelectorTr
toggleValue(value)
setIsDeleteHovered(false)
}}
- className="ml-1 text-foreground-lighter hover:text-foreground-light transition-colors pointer-events-auto"
+ className="ml-1 p-0.5 rounded-xs cursor-pointer text-foreground-lighter hover:text-foreground-light hover:bg-surface-400 transition-colors pointer-events-auto"
>
<RemoveIcon size={12} />
</div>
@@ -480,12 +479,9 @@ const MultiSelectorTrigger = React.forwardRef<HTMLButtonElement, MultiSelectorTr
autoFocus={false}
wrapperClassName={cn(
MultiSelectorInlineInputWrapperVariants({ size }),
- SHOULD_WRAP_BADGES && 'min-w-[85px]'
- )}
- className={cn(
- MultiSelectorInlineInputVariants({ size }),
- HAS_TINY_PLACEHOLDER && 'pl-2'
+ SHOULD_WRAP_BADGES && 'min-w-21.25'
)}
+ className={cn(INLINE_INPUT_CLASSES, HAS_TINY_PLACEHOLDER && 'pl-3')}
/>
)}
</div>