Skip to content

Commit

Permalink
fix: Enable keyboard activation of ListBoxFooter components (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmar authored Jul 7, 2023
1 parent e43ee4f commit eb59cbd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/ListBoxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ const ListBoxItem = forwardRef<HTMLDivElement, ListBoxItemProps>(
)
)

type ListBoxFooterProps = ComponentPropsWithRef<'div'> & {
type ListBoxFooterProps = ComponentPropsWithRef<typeof ListBoxFooterInner> & {
children: ReactNode
leftContent?: ReactNode
rightContent?: ReactNode
}
const ListBoxFooterInner = styled.div<{ focused?: boolean }>(
const ListBoxFooterInner = styled.button<{ focused?: boolean }>(
({ theme, focused = false }) => ({
...theme.partials.reset.button,
display: 'flex',
Expand Down Expand Up @@ -193,7 +193,7 @@ const ListBoxFooterInner = styled.div<{ focused?: boolean }>(
: {}),
})
)
const ListBoxFooter = forwardRef<HTMLDivElement, ListBoxFooterProps>(
const ListBoxFooter = forwardRef<HTMLButtonElement, ListBoxFooterProps>(
({ leftContent, rightContent, children, ...props }, ref) => (
<ListBoxFooterInner
tabIndex={0}
Expand Down
13 changes: 5 additions & 8 deletions src/stories/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,11 @@ function TagsTemplate() {
<ComboBox
isOpen={isOpen}
inputValue={inputValue}
onSelectionChange={(selectedKey) => {
if (selectedKey === '$$footer$$') {
setSelectedKeys(new Set([...selectedKeys, newKey]))
setInputValue('')
setIsOpen(false)
} else {
onSelectionChange(selectedKey)
}
onSelectionChange={onSelectionChange}
onFooterClick={() => {
setSelectedKeys(new Set([...selectedKeys, newKey]))
setInputValue('')
setIsOpen(false)
}}
onInputChange={onInputChange}
inputProps={{ placeholder: 'Pick something' }}
Expand Down
8 changes: 6 additions & 2 deletions src/stories/ListBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ function Template() {
const shownStep = 4
const [shownLimit, setShownLimit] = useState<number>(shownStep)

const onFooterClick = () => {
alert('You selected the footer')
}

return (
<Flex
flexDirection="column"
Expand Down Expand Up @@ -185,7 +189,7 @@ function Template() {
setSelectedKey(key)
}}
footerFixed={
<ListBoxFooter onClick={() => alert('You clicked the footer')}>
<ListBoxFooter onClick={onFooterClick}>
Fixed Footer - Default
</ListBoxFooter>
}
Expand Down Expand Up @@ -214,7 +218,7 @@ function Template() {
setSelectedKey(key)
}}
footerFixed={
<ListBoxFooterPlus onClick={() => alert('You clicked the footer')}>
<ListBoxFooterPlus onClick={onFooterClick}>
Fixed Footer - Add
</ListBoxFooterPlus>
}
Expand Down
21 changes: 17 additions & 4 deletions src/stories/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ function Template() {
? `Selections: ${curItems.map((item) => item.label).join(', ')}`
: 'Select items'

const createNewHandler = () => {
alert('You selected "Create new."')
}

return (
<Flex
flexDirection="column"
Expand Down Expand Up @@ -235,7 +239,9 @@ function Template() {
leftContent={<SearchIcon />}
rightContent={<ListBoxItemChipList chips={curItem?.chips} />}
dropdownFooterFixed={
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
<ListBoxFooterPlus onClick={createNewHandler}>
Create new
</ListBoxFooterPlus>
}
>
{items.map(({ key, label, description, chips }) => (
Expand All @@ -260,8 +266,11 @@ function Template() {
}}
defaultOpen={false}
dropdownFooterFixed={
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
<ListBoxFooterPlus onClick={createNewHandler}>
Create new
</ListBoxFooterPlus>
}
onFooterClick={createNewHandler}
triggerButton={
<SelectButton leftContent={curItem ? <CheckIcon /> : <InfoIcon />}>
{customLabel}
Expand Down Expand Up @@ -378,7 +387,9 @@ function Template() {
leftContent={<SearchIcon />}
rightContent={<ListBoxItemChipList chips={curItem?.chips} />}
dropdownFooterFixed={
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
<ListBoxFooterPlus onClick={createNewHandler}>
Create new
</ListBoxFooterPlus>
}
>
{items.map(({ key, label, description, chips }) => (
Expand All @@ -401,7 +412,9 @@ function Template() {
}}
defaultOpen={false}
dropdownFooterFixed={
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
<ListBoxFooterPlus onClick={createNewHandler}>
Create new
</ListBoxFooterPlus>
}
triggerButton={
<SelectButton leftContent={curItem ? <CheckIcon /> : <InfoIcon />}>
Expand Down

0 comments on commit eb59cbd

Please sign in to comment.