Skip to content

Commit

Permalink
fix(useSelect): toggle element labelled by label only
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram committed Nov 23, 2022
1 parent 4c3d3ea commit 061b5b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/hooks/useSelect/__tests__/getToggleButtonProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@ describe('getToggleButtonProps', () => {
const {result} = renderUseSelect()
const toggleButtonProps = result.current.getToggleButtonProps()

expect(toggleButtonProps['aria-labelledby']).toEqual(
`${defaultIds.labelId} ${defaultIds.toggleButtonId}`,
)
expect(toggleButtonProps['aria-labelledby']).toEqual(defaultIds.labelId)
})

test('assign custom value passed by user to aria-labelledby', () => {
const props = {
labelId: 'my-custom-label-id',
toggleButtonId: 'my-custom-toggle-button-id',
}
const {result} = renderUseSelect(props)
const toggleButtonProps = result.current.getToggleButtonProps()

expect(toggleButtonProps['aria-labelledby']).toEqual(
`${props.labelId} ${props.toggleButtonId}`,
)
expect(toggleButtonProps['aria-labelledby']).toEqual(props.labelId)
})

test('assign default value to id', () => {
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 @@ -381,7 +381,7 @@ function useSelect(userProps = {}) {
'aria-controls': elementIds.menuId,
'aria-expanded': latest.current.state.isOpen,
'aria-haspopup': 'listbox',
'aria-labelledby': `${elementIds.labelId} ${elementIds.toggleButtonId}`,
'aria-labelledby': `${elementIds.labelId}`,
id: elementIds.toggleButtonId,
role: 'combobox',
tabIndex: 0,
Expand Down

0 comments on commit 061b5b1

Please sign in to comment.