diff --git a/packages/shoreline/src/components/filter/filter-value.tsx b/packages/shoreline/src/components/filter/filter-value.tsx index 3cf799b402..117466cd71 100644 --- a/packages/shoreline/src/components/filter/filter-value.tsx +++ b/packages/shoreline/src/components/filter/filter-value.tsx @@ -1,5 +1,6 @@ +import { useSelectContext } from '@ariakit/react' import type { ComponentPropsWithoutRef } from 'react' -import { forwardRef } from 'react' +import { forwardRef, useCallback } from 'react' import { useFilterContext } from './filter-context' const valueSeparator = ': ' @@ -13,14 +14,25 @@ export const FilterValue = forwardRef( const filter = useFilterContext() const value = filter?.useState('value') - const isArray = Array.isArray(value) - const isLongArray = isArray && value.length > 1 + const valueIsArray = Array.isArray(value) + const valueIsMultiSelected = valueIsArray && value.length > 1 + + const selectContext = useSelectContext() + const items = selectContext?.useState('items') + + const getValueText = useCallback( + () => + items?.find((item) => + valueIsArray ? item.value === value[0] : item.value === value + )?.element?.innerText, + [value, valueIsArray, items] + ) return ( {value && value.length > 0 && valueSeparator} - {isArray ? value[0] : value} - {isLongArray && `${countPrefix}${value.length - 1}`} + {getValueText()} + {valueIsMultiSelected && `${countPrefix}${value.length - 1}`} ) }