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

Commit

Permalink
fix(Menu): correctly handle isFromKeyboard (#596)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
layershifter authored Dec 12, 2018
1 parent 1ddffea commit 206da99
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix `getKeyDownHandler` to pass props for client's onKeyDown handler @sophieH29 ([#595](https://github.com/stardust-ui/react/pull/595))
- Fix `Popup` not closing on outside click @kuzhelov ([#598](https://github.com/stardust-ui/react/pull/598))
- Fix multiple React's warnings about keys in docs @layershifter ([#602](https://github.com/stardust-ui/react/pull/602))
- Fix incorrect handling of `isFromKeyboard` in `Menu` @layershifter ([#596](https://github.com/stardust-ui/react/pull/596))

### Features
- `Ref` components uses `forwardRef` API by default @layershifter ([#491](https://github.com/stardust-ui/react/pull/491))
Expand Down
1 change: 0 additions & 1 deletion build/gulp/tasks/test-projects/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default {
'Spacebar',
'Tab',
],
'node_modules/what-input/dist/what-input.js': ['ask'],
},
}),
],
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"prop-types": "^15.6.1",
"react-fela": "^7.2.0",
"react-is": "^16.6.3",
"react-popper": "^1.0.2",
"what-input": "^5.1.2"
"react-popper": "^1.0.2"
},
"devDependencies": {
"@babel/standalone": "^7.1.0",
Expand Down
10 changes: 6 additions & 4 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
childrenExist,
customPropTypes,
createShorthandFactory,
isFromKeyboard,
UIComponentProps,
ContentComponentProps,
ChildrenComponentProps,
Expand All @@ -18,7 +19,6 @@ import { buttonBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/types'
import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../types/utils'
import ButtonGroup from './ButtonGroup'
import isFromKeyboard from '../../lib/isFromKeyboard'

export interface ButtonProps
extends UIComponentProps,
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface ButtonProps
}

export interface ButtonState {
[isFromKeyboard.propertyName]: boolean
isFromKeyboard: boolean
}

/**
Expand Down Expand Up @@ -115,7 +115,9 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {

static Group = ButtonGroup

public state = isFromKeyboard.initial
public state = {
isFromKeyboard: false,
}

public renderComponent({
ElementType,
Expand Down Expand Up @@ -171,7 +173,7 @@ class Button extends UIComponent<Extendable<ButtonProps>, ButtonState> {
}

private handleFocus = (e: React.SyntheticEvent) => {
this.setState(isFromKeyboard.state())
this.setState({ isFromKeyboard: isFromKeyboard() })

_.invoke(this.props, 'onFocus', e, this.props)
}
Expand Down
12 changes: 7 additions & 5 deletions src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
ChildrenComponentProps,
ContentComponentProps,
commonPropTypes,
isFromKeyboard,
} from '../../lib'
import Icon from '../Icon/Icon'
import Slot from '../Slot/Slot'
import { menuItemBehavior } from '../../lib/accessibility'
import { Accessibility, AccessibilityActionHandlers } from '../../lib/accessibility/types'
import IsFromKeyboard from '../../lib/isFromKeyboard'
import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../types/utils'

export interface MenuItemProps
Expand Down Expand Up @@ -81,7 +81,7 @@ export interface MenuItemProps
}

export interface MenuItemState {
[IsFromKeyboard.propertyName]: boolean
isFromKeyboard: boolean
}

/**
Expand Down Expand Up @@ -118,7 +118,9 @@ class MenuItem extends UIComponent<Extendable<MenuItemProps>, MenuItemState> {
wrapper: { as: 'li' },
}

state = IsFromKeyboard.initial
state = {
isFromKeyboard: false,
}

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

private handleBlur = (e: React.SyntheticEvent) => {
this.setState(IsFromKeyboard.initial)
this.setState({ isFromKeyboard: false })

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

private handleFocus = (e: React.SyntheticEvent) => {
this.setState(IsFromKeyboard.state())
this.setState({ isFromKeyboard: isFromKeyboard() })

_.invoke(this.props, 'onFocus', e, this.props)
}
Expand Down
19 changes: 5 additions & 14 deletions src/components/RadioGroup/RadioGroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
customPropTypes,
AutoControlledComponent,
createShorthandFactory,
isFromKeyboard,
UIComponentProps,
ChildrenComponentProps,
commonPropTypes,
Expand All @@ -16,7 +17,6 @@ import { ComponentEventHandler, Extendable, ShorthandValue } from '../../../type
import Icon from '../Icon/Icon'
import { Accessibility } from '../../lib/accessibility/types'
import { radioGroupItemBehavior } from '../../lib/accessibility'
import isFromKeyboard from '../../lib/isFromKeyboard'

export interface RadioGroupItemProps extends UIComponentProps, ChildrenComponentProps {
/**
Expand All @@ -41,9 +41,6 @@ export interface RadioGroupItemProps extends UIComponentProps, ChildrenComponent
/** Initial checked value. */
defaultChecked?: boolean

/** Default value for isFromKeyboard (autocontrolled). */
defaultIsFromKeyboard?: boolean

/** A radio item can appear disabled and be unable to change states. */
disabled?: boolean

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

/** Whether focus came from the keyboard (autocontrolled). */
[isFromKeyboard.propertyName]?: boolean

/** A vertical radio group displays elements vertically. */
vertical?: boolean
}

export interface RadioGroupItemState {
checked: boolean
[isFromKeyboard.propertyName]: boolean
isFromKeyboard: boolean
}

/**
Expand All @@ -116,11 +110,8 @@ class RadioGroupItem extends AutoControlledComponent<
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
checked: PropTypes.bool,
defaultChecked: PropTypes.bool,
/** Default value for isFromKeyboard (autocontrolled). */
defaultIsFromKeyboard: PropTypes.bool,
disabled: PropTypes.bool,
icon: customPropTypes.itemShorthand,
isFromKeyboard: PropTypes.bool,
label: customPropTypes.nodeContent,
name: PropTypes.string,
onBlur: PropTypes.func,
Expand All @@ -137,7 +128,7 @@ class RadioGroupItem extends AutoControlledComponent<
accessibility: radioGroupItemBehavior as Accessibility,
}

static autoControlledProps = ['checked', isFromKeyboard.propertyName]
static autoControlledProps = ['checked']

componentDidUpdate(prevProps, prevState) {
const checked = this.state.checked
Expand Down Expand Up @@ -180,12 +171,12 @@ class RadioGroupItem extends AutoControlledComponent<
}

private handleFocus = (e: React.SyntheticEvent) => {
this.setState(isFromKeyboard.state())
this.setState({ isFromKeyboard: isFromKeyboard() })
_.invoke(this.props, 'onFocus', e, this.props)
}

private handleBlur = (e: React.SyntheticEvent) => {
this.setState(isFromKeyboard.initial)
this.setState({ isFromKeyboard: false })
_.invoke(this.props, 'onBlur', e, this.props)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export {
} from './htmlPropsUtils'

export { default as isBrowser } from './isBrowser'
export { default as typescriptUtils } from './typescriptUtils'
export { default as doesNodeContainClick } from './doesNodeContainClick'
export { default as leven } from './leven'

export { pxToRem } from './fontSizeUtility'
export { customPropTypes }
export { default as createAnimationStyles } from './createAnimationStyles'
export { default as createComponent } from './createStardustComponent'
export * from './whatInput'

export * from './commonPropInterfaces'
export { commonPropTypes }
18 changes: 0 additions & 18 deletions src/lib/isFromKeyboard.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/lib/typescriptUtils.ts

This file was deleted.

Loading

0 comments on commit 206da99

Please sign in to comment.