fix(SW-1509): add support for default selected key
fixed padding per list item
This commit is contained in:
@@ -22,6 +22,15 @@ export const Default: Story = {
|
||||
},
|
||||
}
|
||||
|
||||
export const DefaultSelected: Story = {
|
||||
args: {
|
||||
items: ['Foo', 'Bar', 'Baz'],
|
||||
label: 'Select an item',
|
||||
name: 'foo',
|
||||
defaultSelectedKey: 'Foo',
|
||||
},
|
||||
}
|
||||
|
||||
export const ObjectItem: Story = {
|
||||
args: {
|
||||
items: [
|
||||
|
||||
@@ -88,22 +88,27 @@ export function Select({
|
||||
|
||||
<Popover className={styles.popover} shouldFlip={false}>
|
||||
<ListBox className={styles.listBox}>
|
||||
{items.map((item, idx) => (
|
||||
<Typography variant="Body/Paragraph/mdRegular" key={idx}>
|
||||
{typeof item === 'object' ? (
|
||||
<SelectItem
|
||||
icon={item.icon || itemIcon}
|
||||
isDisabled={item.isDisabled}
|
||||
>
|
||||
{item.label}
|
||||
</SelectItem>
|
||||
) : (
|
||||
<SelectItem icon={itemIcon} isDisabled={isDisabled}>
|
||||
{item.toString()}
|
||||
</SelectItem>
|
||||
)}
|
||||
</Typography>
|
||||
))}
|
||||
{items.map((item) =>
|
||||
typeof item === 'object' ? (
|
||||
<SelectItem
|
||||
key={item.label}
|
||||
id={item.label}
|
||||
icon={item.icon || itemIcon}
|
||||
isDisabled={item.isDisabled}
|
||||
>
|
||||
{item.label}
|
||||
</SelectItem>
|
||||
) : (
|
||||
<SelectItem
|
||||
key={item}
|
||||
id={item}
|
||||
icon={itemIcon}
|
||||
isDisabled={isDisabled}
|
||||
>
|
||||
{item.toString()}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
</ListBox>
|
||||
</Popover>
|
||||
</AriaSelect>
|
||||
|
||||
@@ -81,22 +81,27 @@ export function SelectFilter({
|
||||
offset={22}
|
||||
>
|
||||
<ListBox className={styles.listBox}>
|
||||
{items.map((item, idx) => (
|
||||
<Typography variant="Body/Paragraph/mdRegular" key={idx}>
|
||||
{typeof item === 'object' ? (
|
||||
<SelectItem
|
||||
icon={item.icon || itemIcon}
|
||||
isDisabled={item.isDisabled}
|
||||
>
|
||||
{item.label}
|
||||
</SelectItem>
|
||||
) : (
|
||||
<SelectItem icon={itemIcon} isDisabled={isDisabled}>
|
||||
{item.toString()}
|
||||
</SelectItem>
|
||||
)}
|
||||
</Typography>
|
||||
))}
|
||||
{items.map((item) =>
|
||||
typeof item === 'object' ? (
|
||||
<SelectItem
|
||||
key={item.label}
|
||||
id={item.label}
|
||||
icon={item.icon || itemIcon}
|
||||
isDisabled={item.isDisabled}
|
||||
>
|
||||
{item.label}
|
||||
</SelectItem>
|
||||
) : (
|
||||
<SelectItem
|
||||
key={item}
|
||||
id={item}
|
||||
icon={itemIcon}
|
||||
isDisabled={isDisabled}
|
||||
>
|
||||
{item.toString()}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
</ListBox>
|
||||
</Popover>
|
||||
</ComboBox>
|
||||
|
||||
@@ -4,12 +4,20 @@ import styles from './select.module.css'
|
||||
import { MaterialIcon } from '../Icons/MaterialIcon'
|
||||
import { SelectItemProps } from './types'
|
||||
|
||||
export function SelectItem({ children, icon, isDisabled }: SelectItemProps) {
|
||||
export function SelectItem({
|
||||
children,
|
||||
icon,
|
||||
isDisabled,
|
||||
...props
|
||||
}: SelectItemProps) {
|
||||
const iconColor = isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default'
|
||||
|
||||
return (
|
||||
<ListBoxItem
|
||||
className={styles.listBoxItem}
|
||||
textValue={children}
|
||||
isDisabled={isDisabled}
|
||||
{...props}
|
||||
>
|
||||
{({ isSelected }) => (
|
||||
<>
|
||||
@@ -17,7 +25,7 @@ export function SelectItem({ children, icon, isDisabled }: SelectItemProps) {
|
||||
<MaterialIcon
|
||||
icon={icon}
|
||||
size={24}
|
||||
color={isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default'}
|
||||
color={iconColor}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user