Skip to content

Commit

Permalink
fix(hooks): return boolean for aria-selected (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram authored May 17, 2024
1 parent 4bf894b commit ee2a828
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
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

0 comments on commit ee2a828

Please sign in to comment.