1
0
mirror of synced 2025-12-21 02:46:50 -05:00
Files
docs/components/page-header/ProductPicker.tsx
Robert Sese d0db00cd98 a11y: match picker label with current selection (#24321)
* Match label with selection

* defaultText is a better default

Co-authored-by: Peter Bengtsson <peterbe@github.com>

* No longer used

* Also no longer used

* No longer used in the dropdown pickers

* Add translation strings for pickers

* Use translated strings in picker components

Co-authored-by: Peter Bengtsson <peterbe@github.com>
2022-01-19 18:43:31 +00:00

37 lines
1.1 KiB
TypeScript

import { useRouter } from 'next/router'
import { Link } from 'components/Link'
import { useMainContext } from 'components/context/MainContext'
import { LinkExternalIcon } from '@primer/octicons-react'
import { Picker } from 'components/ui/Picker'
import { useTranslation } from 'components/hooks/useTranslation'
export const ProductPicker = () => {
const router = useRouter()
const { activeProducts, currentProduct } = useMainContext()
const { t } = useTranslation('picker')
return (
<Picker
variant="inline"
data-testid="product-picker"
data-current-product-path={currentProduct?.href}
defaultText={t('product_picker_default_text')}
options={activeProducts.map((product) => ({
text: product.name,
selected: product.name === currentProduct?.name,
item: (
<Link href={`${product.external ? '' : `/${router.locale}`}${product.href}`}>
{product.name}
{product.external && (
<span className="ml-1">
<LinkExternalIcon size="small" />
</span>
)}
</Link>
),
}))}
/>
)
}