Skip to content

Commit

Permalink
fix(useCombobox): pass down missing disabled prop in prop getters (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya authored and silviuaavram committed Jan 8, 2020
1 parent 4fab769 commit 02c5c66
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 28 deletions.
42 changes: 21 additions & 21 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{
"dist/downshift.cjs.js": {
"bundled": 113146,
"minified": 52111,
"gzipped": 11538
"bundled": 113058,
"minified": 52081,
"gzipped": 11521
},
"preact/dist/downshift.cjs.js": {
"bundled": 111864,
"minified": 51073,
"gzipped": 11437
"bundled": 111776,
"minified": 51043,
"gzipped": 11421
},
"preact/dist/downshift.umd.js": {
"bundled": 140209,
"minified": 48040,
"gzipped": 13116
"bundled": 140807,
"minified": 50220,
"gzipped": 13039
},
"preact/dist/downshift.umd.min.js": {
"bundled": 124057,
"minified": 40510,
"gzipped": 11333
"bundled": 124445,
"minified": 40311,
"gzipped": 11141
},
"dist/downshift.umd.min.js": {
"bundled": 128292,
"minified": 41826,
"gzipped": 11867
"bundled": 128680,
"minified": 41630,
"gzipped": 11599
},
"dist/downshift.umd.js": {
"bundled": 169834,
"minified": 56952,
"gzipped": 15717
"bundled": 170432,
"minified": 59160,
"gzipped": 15594
},
"preact/dist/downshift.esm.js": {
"bundled": 111365,
"minified": 50648,
"gzipped": 11370,
"bundled": 111277,
"minified": 50618,
"gzipped": 11354,
"treeshaked": {
"rollup": {
"code": 1752,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useCombobox/__tests__/getInputProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('getInputProps', () => {
expect(inputProps.onChange).toBeUndefined()
expect(inputProps.onKeyDown).toBeUndefined()
expect(inputProps.onBlur).toBeUndefined()
expect(inputProps.disabled).toBe(true)
})
})

Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useCombobox/__tests__/getItemProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ describe('getItemProps', () => {

test("handlers are not called if it's disabled", () => {
const {result} = setupHook()
const inputProps = result.current.getInputProps({
const itemProps = result.current.getItemProps({
disabled: true,
index: 0,
})

expect(inputProps.onClick).toBeUndefined()
expect(inputProps.onMouseMove).toBeUndefined()
expect(itemProps.onClick).toBeUndefined()
expect(itemProps.onMouseMove).toBeUndefined()
expect(itemProps.disabled).toBe(true)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('getToggleButtonProps', () => {
})

expect(toggleButtonProps.onClick).toBeUndefined()
expect(toggleButtonProps.disabled).toBe(true)
})
})

Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useCombobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ function useCombobox(userProps = {}) {
onMouseMove,
onClick,
onPress,
disabled,
...rest
} = {}) => {
const itemIndex = getItemIndex(index, item, items)
Expand All @@ -286,7 +285,7 @@ function useCombobox(userProps = {}) {
role: 'option',
...(itemIndex === highlightedIndex && {'aria-selected': true}),
id: getItemId(itemIndex),
...(!disabled && {
...(!rest.disabled && {
onMouseMove: callAllEventHandlers(onMouseMove, () => {
itemHandleMouseMove(itemIndex)
}),
Expand All @@ -302,7 +301,6 @@ function useCombobox(userProps = {}) {
onPress,
refKey = 'ref',
ref,
disabled,
...rest
} = {}) => {
return {
Expand All @@ -311,7 +309,7 @@ function useCombobox(userProps = {}) {
}),
id: toggleButtonId,
tabIndex: -1,
...(!disabled && {
...(!rest.disabled && {
...(isReactNative
? /* istanbul ignore next (react-native) */ {
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick),
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useSelect/__tests__/getItemProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('getItemProps', () => {

expect(itemProps.onMouseMove).toBeUndefined()
expect(itemProps.onClick).toBeUndefined()
expect(itemProps.disabled).toBe(true)
})
})

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useSelect/__tests__/getToggleButtonProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('getToggleButtonProps', () => {

expect(toggleButtonProps.onClick).toBeUndefined()
expect(toggleButtonProps.onKeyDown).toBeUndefined()
expect(toggleButtonProps.disabled).toBe(true)
})
})

Expand Down

0 comments on commit 02c5c66

Please sign in to comment.