Skip to content

Commit

Permalink
fix(useSelect): correct getLabelProps return type (#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram authored Dec 29, 2023
1 parent 53dd723 commit a5d6310
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
30 changes: 13 additions & 17 deletions src/hooks/useSelect/__tests__/getLabelProps.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {act, screen} from '@testing-library/react'
import {screen} from '@testing-library/react'
import {renderSelect, renderUseSelect} from '../testUtils'
import {defaultIds, getToggleButton, user} from '../../testUtils'

Expand Down Expand Up @@ -53,15 +53,13 @@ describe('getLabelProps', () => {
const mockToggleButton = {focus: jest.fn()}
const {result} = renderUseSelect()

act(() => {
const {onClick} = result.current.getLabelProps({
onClick: userOnClick,
})
const {ref} = result.current.getToggleButtonProps()
ref(mockToggleButton)

onClick({})
const {onClick} = result.current.getLabelProps({
onClick: userOnClick,
})
const {ref} = result.current.getToggleButtonProps()
ref(mockToggleButton)

onClick({})

expect(userOnClick).toHaveBeenCalledTimes(1)
expect(mockToggleButton.focus).toHaveBeenCalledTimes(1)
Expand All @@ -74,15 +72,13 @@ describe('getLabelProps', () => {
const mockToggleButton = {focus: jest.fn()}
const {result} = renderUseSelect()

act(() => {
const {onClick} = result.current.getLabelProps({
onClick: userOnClick,
})
const {ref} = result.current.getToggleButtonProps()
ref(mockToggleButton)

onClick({})
const {onClick} = result.current.getLabelProps({
onClick: userOnClick,
})
const {ref} = result.current.getToggleButtonProps()
ref(mockToggleButton)

onClick({})

expect(userOnClick).toHaveBeenCalledTimes(1)
expect(mockToggleButton.focus).not.toHaveBeenCalled()
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ export interface UseSelectGetToggleButtonReturnValue
tabIndex: 0
}

export interface UseSelectGetLabelPropsOptions extends GetLabelPropsOptions {
export interface UseSelectGetLabelPropsOptions extends GetLabelPropsOptions {}
export interface UseSelectGetLabelPropsReturnValue
extends GetLabelPropsReturnValue {
onClick: React.MouseEventHandler
}
export interface UseSelectGetLabelPropsReturnValue
extends GetLabelPropsReturnValue {}

export interface UseSelectGetItemPropsOptions<Item>
extends Omit<GetItemPropsOptions<Item>, 'disabled'>,
Expand Down

0 comments on commit a5d6310

Please sign in to comment.