Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 206da99

Browse files
authored
fix(Menu): correctly handle isFromKeyboard (#596)
* fix(Menu): correctly handle `isFromKeyboard` * fix mock * fix exports * cleanup * remove unused stuff * fix SSR * remove intent * remove what-input from rollup config * remove `isFromKeyboard` from ACC * add entry to changelog
1 parent 1ddffea commit 206da99

File tree

13 files changed

+261
-65
lines changed

13 files changed

+261
-65
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3737
- Fix `getKeyDownHandler` to pass props for client's onKeyDown handler @sophieH29 ([#595](https://github.com/stardust-ui/react/pull/595))
3838
- Fix `Popup` not closing on outside click @kuzhelov ([#598](https://github.com/stardust-ui/react/pull/598))
3939
- Fix multiple React's warnings about keys in docs @layershifter ([#602](https://github.com/stardust-ui/react/pull/602))
40+
- Fix incorrect handling of `isFromKeyboard` in `Menu` @layershifter ([#596](https://github.com/stardust-ui/react/pull/596))
4041

4142
### Features
4243
- `Ref` components uses `forwardRef` API by default @layershifter ([#491](https://github.com/stardust-ui/react/pull/491))

build/gulp/tasks/test-projects/rollup/rollup.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export default {
6060
'Spacebar',
6161
'Tab',
6262
],
63-
'node_modules/what-input/dist/what-input.js': ['ask'],
6463
},
6564
}),
6665
],

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@
7070
"prop-types": "^15.6.1",
7171
"react-fela": "^7.2.0",
7272
"react-is": "^16.6.3",
73-
"react-popper": "^1.0.2",
74-
"what-input": "^5.1.2"
73+
"react-popper": "^1.0.2"
7574
},
7675
"devDependencies": {
7776
"@babel/standalone": "^7.1.0",

src/components/Button/Button.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
childrenExist,
88
customPropTypes,
99
createShorthandFactory,
10+
isFromKeyboard,
1011
UIComponentProps,
1112
ContentComponentProps,
1213
ChildrenComponentProps,
@@ -18,7 +19,6 @@ import { buttonBehavior } from '../../lib/accessibility'
1819
import { Accessibility } from '../../lib/accessibility/types'
1920
import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../types/utils'
2021
import ButtonGroup from './ButtonGroup'
21-
import isFromKeyboard from '../../lib/isFromKeyboard'
2222

2323
export interface ButtonProps
2424
extends UIComponentProps,
@@ -73,7 +73,7 @@ export interface ButtonProps
7373
}
7474

7575
export interface ButtonState {
76-
[isFromKeyboard.propertyName]: boolean
76+
isFromKeyboard: boolean
7777
}
7878

7979
/**
@@ -115,7 +115,9 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {
115115

116116
static Group = ButtonGroup
117117

118-
public state = isFromKeyboard.initial
118+
public state = {
119+
isFromKeyboard: false,
120+
}
119121

120122
public renderComponent({
121123
ElementType,
@@ -171,7 +173,7 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {
171173
}
172174

173175
private handleFocus = (e: React.SyntheticEvent) => {
174-
this.setState(isFromKeyboard.state())
176+
this.setState({ isFromKeyboard: isFromKeyboard() })
175177

176178
_.invoke(this.props, 'onFocus', e, this.props)
177179
}

src/components/Menu/MenuItem.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212
ChildrenComponentProps,
1313
ContentComponentProps,
1414
commonPropTypes,
15+
isFromKeyboard,
1516
} from '../../lib'
1617
import Icon from '../Icon/Icon'
1718
import Slot from '../Slot/Slot'
1819
import { menuItemBehavior } from '../../lib/accessibility'
1920
import { Accessibility, AccessibilityActionHandlers } from '../../lib/accessibility/types'
20-
import IsFromKeyboard from '../../lib/isFromKeyboard'
2121
import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../types/utils'
2222

2323
export interface MenuItemProps
@@ -81,7 +81,7 @@ export interface MenuItemProps
8181
}
8282

8383
export interface MenuItemState {
84-
[IsFromKeyboard.propertyName]: boolean
84+
isFromKeyboard: boolean
8585
}
8686

8787
/**
@@ -118,7 +118,9 @@ class MenuItem extends UIComponent<Extendable<MenuItemProps>, MenuItemState> {
118118
wrapper: { as: 'li' },
119119
}
120120

121-
state = IsFromKeyboard.initial
121+
state = {
122+
isFromKeyboard: false,
123+
}
122124

123125
renderComponent({ ElementType, classes, accessibility, rest }) {
124126
const { children, content, icon, wrapper } = this.props
@@ -167,13 +169,13 @@ class MenuItem extends UIComponent<Extendable<MenuItemProps>, MenuItemState> {
167169
}
168170

169171
private handleBlur = (e: React.SyntheticEvent) => {
170-
this.setState(IsFromKeyboard.initial)
172+
this.setState({ isFromKeyboard: false })
171173

172174
_.invoke(this.props, 'onBlur', e, this.props)
173175
}
174176

175177
private handleFocus = (e: React.SyntheticEvent) => {
176-
this.setState(IsFromKeyboard.state())
178+
this.setState({ isFromKeyboard: isFromKeyboard() })
177179

178180
_.invoke(this.props, 'onFocus', e, this.props)
179181
}

src/components/RadioGroup/RadioGroupItem.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
customPropTypes,
88
AutoControlledComponent,
99
createShorthandFactory,
10+
isFromKeyboard,
1011
UIComponentProps,
1112
ChildrenComponentProps,
1213
commonPropTypes,
@@ -16,7 +17,6 @@ import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../type
1617
import Icon from '../Icon/Icon'
1718
import { Accessibility } from '../../lib/accessibility/types'
1819
import { radioGroupItemBehavior } from '../../lib/accessibility'
19-
import isFromKeyboard from '../../lib/isFromKeyboard'
2020

2121
export interface RadioGroupItemProps extends UIComponentProps, ChildrenComponentProps {
2222
/**
@@ -41,9 +41,6 @@ export interface RadioGroupItemProps extends UIComponentProps, ChildrenComponent
4141
/** Initial checked value. */
4242
defaultChecked?: boolean
4343

44-
/** Default value for isFromKeyboard (autocontrolled). */
45-
defaultIsFromKeyboard?: boolean
46-
4744
/** A radio item can appear disabled and be unable to change states. */
4845
disabled?: boolean
4946

@@ -80,16 +77,13 @@ export interface RadioGroupItemProps extends UIComponentProps, ChildrenComponent
8077
/** The HTML input value. */
8178
value?: string | number
8279

83-
/** Whether focus came from the keyboard (autocontrolled). */
84-
[isFromKeyboard.propertyName]?: boolean
85-
8680
/** A vertical radio group displays elements vertically. */
8781
vertical?: boolean
8882
}
8983

9084
export interface RadioGroupItemState {
9185
checked: boolean
92-
[isFromKeyboard.propertyName]: boolean
86+
isFromKeyboard: boolean
9387
}
9488

9589
/**
@@ -116,11 +110,8 @@ class RadioGroupItem extends AutoControlledComponent<
116110
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
117111
checked: PropTypes.bool,
118112
defaultChecked: PropTypes.bool,
119-
/** Default value for isFromKeyboard (autocontrolled). */
120-
defaultIsFromKeyboard: PropTypes.bool,
121113
disabled: PropTypes.bool,
122114
icon: customPropTypes.itemShorthand,
123-
isFromKeyboard: PropTypes.bool,
124115
label: customPropTypes.nodeContent,
125116
name: PropTypes.string,
126117
onBlur: PropTypes.func,
@@ -137,7 +128,7 @@ class RadioGroupItem extends AutoControlledComponent<
137128
accessibility: radioGroupItemBehavior as Accessibility,
138129
}
139130

140-
static autoControlledProps = ['checked', isFromKeyboard.propertyName]
131+
static autoControlledProps = ['checked']
141132

142133
componentDidUpdate(prevProps, prevState) {
143134
const checked = this.state.checked
@@ -180,12 +171,12 @@ class RadioGroupItem extends AutoControlledComponent<
180171
}
181172

182173
private handleFocus = (e: React.SyntheticEvent) => {
183-
this.setState(isFromKeyboard.state())
174+
this.setState({ isFromKeyboard: isFromKeyboard() })
184175
_.invoke(this.props, 'onFocus', e, this.props)
185176
}
186177

187178
private handleBlur = (e: React.SyntheticEvent) => {
188-
this.setState(isFromKeyboard.initial)
179+
this.setState({ isFromKeyboard: false })
189180
_.invoke(this.props, 'onBlur', e, this.props)
190181
}
191182

src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export {
2727
} from './htmlPropsUtils'
2828

2929
export { default as isBrowser } from './isBrowser'
30-
export { default as typescriptUtils } from './typescriptUtils'
3130
export { default as doesNodeContainClick } from './doesNodeContainClick'
3231
export { default as leven } from './leven'
3332

3433
export { pxToRem } from './fontSizeUtility'
3534
export { customPropTypes }
3635
export { default as createAnimationStyles } from './createAnimationStyles'
3736
export { default as createComponent } from './createStardustComponent'
37+
export * from './whatInput'
3838

3939
export * from './commonPropInterfaces'
4040
export { commonPropTypes }

src/lib/isFromKeyboard.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/lib/typescriptUtils.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)