Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(hooks): return boolean for aria-selected #1603

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/hooks/useCombobox/__tests__/getItemProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ describe('getItemProps', () => {
const {result} = renderUseCombobox({highlightedIndex: 2})
const itemProps = result.current.getItemProps({index: 2})

expect(itemProps['aria-selected']).toEqual('true')
expect(itemProps['aria-selected']).toEqual(true)
})

test("assign 'false' to aria-selected if item is not highlighted", () => {
const {result} = renderUseCombobox({highlightedIndex: 1})
const itemProps = result.current.getItemProps({index: 2})

expect(itemProps['aria-selected']).toEqual('false')
expect(itemProps['aria-selected']).toEqual(false)
})

test("click handler is not called if it's disabled", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCombobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function useCombobox(userProps = {}) {
}
}),
'aria-disabled': disabled,
'aria-selected': `${index === latestState.highlightedIndex}`,
'aria-selected': index === latestState.highlightedIndex,
id: elementIds.getItemId(index),
role: 'option',
...(!disabled && {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useSelect/__tests__/getItemProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ describe('getItemProps', () => {
const item2Props = result.current.getItemProps({index: 2})
const item3Props = result.current.getItemProps({index: 3})

expect(item2Props['aria-selected']).toEqual('false')
expect(item3Props['aria-selected']).toEqual('true')
expect(item2Props['aria-selected']).toEqual(false)
expect(item3Props['aria-selected']).toEqual(true)
})

test("assign 'false' to aria-selected if item is not highlighted", () => {
const {result} = renderUseSelect({highlightedIndex: 1})
const itemProps = result.current.getItemProps({index: 2})

expect(itemProps['aria-selected']).toEqual('false')
expect(itemProps['aria-selected']).toEqual(false)
})

test('omit click handler when disabled', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function useSelect(userProps = {}) {
}
}),
'aria-disabled': disabled,
'aria-selected': `${item === latestState.selectedItem}`,
'aria-selected': item === latestState.selectedItem,
id: elementIds.getItemId(index),
role: 'option',
...rest,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelect/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function DropdownSelect({renderSpy, renderItem, ...props}) {
<li
data-testid={dataTestIds.item(index)}
key={`${stringItem}${index}`}
{...getItemProps({item, index, disabled: item.disabled})}
{...getItemProps({item, index})}
>
{stringItem}
</li>
Expand Down
Loading