Skip to content

Commit

Permalink
fix: select component wouldn't scroll with long list (#757)
Browse files Browse the repository at this point in the history
* fix(components): update styles in Select component for scrolling behavior

* fix(core): update selects to use item-aligned select content
  • Loading branch information
chanceaclark committed Apr 12, 2024
1 parent 6a6af43 commit dac0199
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-roses-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Update cart select components to use the item-aligned select content in order to scroll with large Select content.
5 changes: 5 additions & 0 deletions .changeset/three-hairs-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/components": patch
---

Update styles to scroll when Select content is long.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const ShippingInfo = ({
placeholder={t('countryPlaceholder')}
value={formValues.country}
>
<SelectContent>
<SelectContent position="item-aligned">
{shippingCountries.map(({ id, countryCode, name }) => {
return (
<SelectItem key={id} value={`${countryCode}-${id}`}>
Expand All @@ -179,7 +179,7 @@ export const ShippingInfo = ({
placeholder={t('statePlaceholder')}
value={formValues.state}
>
<SelectContent>
<SelectContent position="item-aligned">
{formValues.states.map(({ id, state }) => {
return (
<SelectItem key={id} value={state}>
Expand Down
16 changes: 12 additions & 4 deletions packages/components/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ type SelectContentType = typeof SelectPrimitive.Content;
const SelectContent = forwardRef<
ElementRef<SelectContentType>,
ComponentPropsWithRef<SelectContentType>
>(({ children, className, ...props }, ref) => {
>(({ children, className, position = 'popper', ...props }, ref) => {
return (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
position="popper"
position={position}
{...props}
className={cn(
'max-h-radix-select-content-available-height relative w-full bg-white shadow-md data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
'max-h-radix-select-content-available-height relative w-full bg-white shadow-md',
position === 'popper' &&
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
className,
)}
ref={ref}
>
<SelectPrimitive.Viewport className="h-radix-select-content-available-height w-full min-w-[var(--radix-select-trigger-width)]">
<SelectPrimitive.Viewport
className={cn(
'w-full',
position === 'popper' &&
'h-[var(--radix-select-trigger-height)] min-w-[var(--radix-select-trigger-width)]',
)}
>
{children}
</SelectPrimitive.Viewport>
</SelectPrimitive.Content>
Expand Down

0 comments on commit dac0199

Please sign in to comment.