From ebc467e666767eefd294b2002953c4e2ecd3e703 Mon Sep 17 00:00:00 2001 From: Jorge Moya Date: Wed, 22 May 2024 13:35:59 -0500 Subject: [PATCH] fix(core): make Select scrollable with popper positioning --- .changeset/cuddly-dolphins-sparkle.md | 5 +++ .../cart/_components/shipping-info/index.tsx | 4 +- .../fields/picklist-or-text.tsx | 2 +- .../fields/picklist.tsx | 2 +- core/components/ui/select/select.tsx | 39 ++++++++++++++++--- 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 .changeset/cuddly-dolphins-sparkle.md diff --git a/.changeset/cuddly-dolphins-sparkle.md b/.changeset/cuddly-dolphins-sparkle.md new file mode 100644 index 000000000..531171785 --- /dev/null +++ b/.changeset/cuddly-dolphins-sparkle.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Make select scrollable with popover functionality. diff --git a/core/app/[locale]/(default)/cart/_components/shipping-info/index.tsx b/core/app/[locale]/(default)/cart/_components/shipping-info/index.tsx index 7c50c36be..793ed633e 100644 --- a/core/app/[locale]/(default)/cart/_components/shipping-info/index.tsx +++ b/core/app/[locale]/(default)/cart/_components/shipping-info/index.tsx @@ -157,7 +157,7 @@ export const ShippingInfo = ({ placeholder={t('countryPlaceholder')} value={formValues.country} > - + {shippingCountries.map(({ id, countryCode, name }) => { return ( @@ -180,7 +180,7 @@ export const ShippingInfo = ({ placeholder={t('statePlaceholder')} value={formValues.state} > - + {formValues.states.map(({ id, state }) => { return ( diff --git a/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist-or-text.tsx b/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist-or-text.tsx index 2749257ec..7a514c450 100644 --- a/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist-or-text.tsx +++ b/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist-or-text.tsx @@ -42,7 +42,7 @@ export const PicklistOrText = ({ defaultValue, field, name, options }: PicklistO placeholder={t('stateProvincePrefix')} required={field.isRequired} > - + {options.map(({ entityId, label }) => { return ( diff --git a/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist.tsx b/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist.tsx index 2faaead44..cfa7d5b22 100644 --- a/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist.tsx +++ b/core/app/[locale]/(default)/login/register-customer/_components/register-customer-form/fields/picklist.tsx @@ -33,7 +33,7 @@ export const Picklist = ({ defaultValue, field, name, onChange, options }: Pickl placeholder={field.choosePrefix} required={field.isRequired} > - + {options.map(({ entityId, label }) => ( {label} diff --git a/core/components/ui/select/select.tsx b/core/components/ui/select/select.tsx index 06e6b8b54..f408c2697 100644 --- a/core/components/ui/select/select.tsx +++ b/core/components/ui/select/select.tsx @@ -1,6 +1,6 @@ import * as SelectPrimitive from '@radix-ui/react-select'; import { cva } from 'class-variance-authority'; -import { Check, ChevronDown } from 'lucide-react'; +import { Check, ChevronDown, ChevronDownIcon, ChevronUpIcon } from 'lucide-react'; import { ComponentPropsWithRef, ElementRef, forwardRef } from 'react'; import { cn } from '~/lib/utils'; @@ -30,7 +30,6 @@ interface SelectProps extends ComponentPropsWithRef { id?: string; } -// We need to pass the ref to the Trigger component so, we need to type it as such. const Select = forwardRef, SelectProps>( ({ children, placeholder, className, variant, 'aria-label': ariaLabel, id, ...props }, ref) => { return ( @@ -42,7 +41,6 @@ const Select = forwardRef, SelectProps>( ref={ref} > - {/* TODO: For the sake of moving fast we are leaving this in, but in the future we need to figure out how enable custom icons */} @@ -58,6 +56,36 @@ Select.displayName = SelectPrimitive.Root.displayName; type SelectContentType = typeof SelectPrimitive.Content; +const SelectScrollUpButton = forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); + +SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName; + +const SelectScrollDownButton = forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); + +SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName; + const SelectContent = forwardRef< ElementRef, ComponentPropsWithRef @@ -68,13 +96,14 @@ const SelectContent = forwardRef< position={position} {...props} className={cn( - 'max-h-radix-select-content-available-height relative w-full bg-white shadow-md', + 'max-h-radix-select-content-available-height relative z-50 max-h-96 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} > + {children} + ); @@ -105,7 +135,6 @@ const SelectItem = forwardRef, ComponentPropsWithRef< ref={ref} > {children} - {/* TODO: For the sake of moving fast we are leaving this in, but in the future we need to figure out how enable custom indicators */}