Skip to content

Commit eb59cbd

Browse files
authored
fix: Enable keyboard activation of ListBoxFooter components (#503)
1 parent e43ee4f commit eb59cbd

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

src/components/ListBoxItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ const ListBoxItem = forwardRef<HTMLDivElement, ListBoxItemProps>(
155155
)
156156
)
157157

158-
type ListBoxFooterProps = ComponentPropsWithRef<'div'> & {
158+
type ListBoxFooterProps = ComponentPropsWithRef<typeof ListBoxFooterInner> & {
159159
children: ReactNode
160160
leftContent?: ReactNode
161161
rightContent?: ReactNode
162162
}
163-
const ListBoxFooterInner = styled.div<{ focused?: boolean }>(
163+
const ListBoxFooterInner = styled.button<{ focused?: boolean }>(
164164
({ theme, focused = false }) => ({
165165
...theme.partials.reset.button,
166166
display: 'flex',
@@ -193,7 +193,7 @@ const ListBoxFooterInner = styled.div<{ focused?: boolean }>(
193193
: {}),
194194
})
195195
)
196-
const ListBoxFooter = forwardRef<HTMLDivElement, ListBoxFooterProps>(
196+
const ListBoxFooter = forwardRef<HTMLButtonElement, ListBoxFooterProps>(
197197
({ leftContent, rightContent, children, ...props }, ref) => (
198198
<ListBoxFooterInner
199199
tabIndex={0}

src/stories/ComboBox.stories.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,11 @@ function TagsTemplate() {
321321
<ComboBox
322322
isOpen={isOpen}
323323
inputValue={inputValue}
324-
onSelectionChange={(selectedKey) => {
325-
if (selectedKey === '$$footer$$') {
326-
setSelectedKeys(new Set([...selectedKeys, newKey]))
327-
setInputValue('')
328-
setIsOpen(false)
329-
} else {
330-
onSelectionChange(selectedKey)
331-
}
324+
onSelectionChange={onSelectionChange}
325+
onFooterClick={() => {
326+
setSelectedKeys(new Set([...selectedKeys, newKey]))
327+
setInputValue('')
328+
setIsOpen(false)
332329
}}
333330
onInputChange={onInputChange}
334331
inputProps={{ placeholder: 'Pick something' }}

src/stories/ListBox.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ function Template() {
147147
const shownStep = 4
148148
const [shownLimit, setShownLimit] = useState<number>(shownStep)
149149

150+
const onFooterClick = () => {
151+
alert('You selected the footer')
152+
}
153+
150154
return (
151155
<Flex
152156
flexDirection="column"
@@ -185,7 +189,7 @@ function Template() {
185189
setSelectedKey(key)
186190
}}
187191
footerFixed={
188-
<ListBoxFooter onClick={() => alert('You clicked the footer')}>
192+
<ListBoxFooter onClick={onFooterClick}>
189193
Fixed Footer - Default
190194
</ListBoxFooter>
191195
}
@@ -214,7 +218,7 @@ function Template() {
214218
setSelectedKey(key)
215219
}}
216220
footerFixed={
217-
<ListBoxFooterPlus onClick={() => alert('You clicked the footer')}>
221+
<ListBoxFooterPlus onClick={onFooterClick}>
218222
Fixed Footer - Add
219223
</ListBoxFooterPlus>
220224
}

src/stories/Select.stories.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ function Template() {
191191
? `Selections: ${curItems.map((item) => item.label).join(', ')}`
192192
: 'Select items'
193193

194+
const createNewHandler = () => {
195+
alert('You selected "Create new."')
196+
}
197+
194198
return (
195199
<Flex
196200
flexDirection="column"
@@ -235,7 +239,9 @@ function Template() {
235239
leftContent={<SearchIcon />}
236240
rightContent={<ListBoxItemChipList chips={curItem?.chips} />}
237241
dropdownFooterFixed={
238-
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
242+
<ListBoxFooterPlus onClick={createNewHandler}>
243+
Create new
244+
</ListBoxFooterPlus>
239245
}
240246
>
241247
{items.map(({ key, label, description, chips }) => (
@@ -260,8 +266,11 @@ function Template() {
260266
}}
261267
defaultOpen={false}
262268
dropdownFooterFixed={
263-
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
269+
<ListBoxFooterPlus onClick={createNewHandler}>
270+
Create new
271+
</ListBoxFooterPlus>
264272
}
273+
onFooterClick={createNewHandler}
265274
triggerButton={
266275
<SelectButton leftContent={curItem ? <CheckIcon /> : <InfoIcon />}>
267276
{customLabel}
@@ -378,7 +387,9 @@ function Template() {
378387
leftContent={<SearchIcon />}
379388
rightContent={<ListBoxItemChipList chips={curItem?.chips} />}
380389
dropdownFooterFixed={
381-
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
390+
<ListBoxFooterPlus onClick={createNewHandler}>
391+
Create new
392+
</ListBoxFooterPlus>
382393
}
383394
>
384395
{items.map(({ key, label, description, chips }) => (
@@ -401,7 +412,9 @@ function Template() {
401412
}}
402413
defaultOpen={false}
403414
dropdownFooterFixed={
404-
<ListBoxFooterPlus>Create new</ListBoxFooterPlus>
415+
<ListBoxFooterPlus onClick={createNewHandler}>
416+
Create new
417+
</ListBoxFooterPlus>
405418
}
406419
triggerButton={
407420
<SelectButton leftContent={curItem ? <CheckIcon /> : <InfoIcon />}>

0 commit comments

Comments
 (0)