Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Multiselect, NumericStepper, Radio & RadioGroup lint issues #1212

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion react/components/MultiSelect/DropdownList.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default class DropdownList extends PureComponent {
key={index}
onClick={() => this.handleSelect(index)}
onMouseEnter={() => this.handleFocus(index)}
role="menuitem"
tabIndex="0"
onKeyPress={() => null}
/>
)
})
Expand All @@ -44,7 +47,9 @@ export default class DropdownList extends PureComponent {
dangerouslySetInnerHTML={{ __html: emptyState }}
/>
) : (
<ul className="ph0 mv0 list">{optionList}</ul>
<ul role="menu" className="ph0 mv0 list">
{optionList}
</ul>
)

return (
Expand Down
31 changes: 16 additions & 15 deletions react/components/NumericStepper/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-globals */
import React, { Component } from 'react'
import PropTypes from 'prop-types'

Expand All @@ -6,7 +7,7 @@ import styles from '../Input/Input.css'
const normalizeMin = min => (min == null ? -Infinity : min)
const normalizeMax = max => (max == null ? Infinity : max)

const validateValue = (value, min, max, defaultValue) => {
const validateValue = ({ value, min, max, defaultValue }) => {
// This function always return a valid numeric value from the current input.
// Compare with the function validateDisplayValue
min = normalizeMin(min)
Expand Down Expand Up @@ -77,12 +78,12 @@ class NumericStepper extends Component {
static getDerivedStateFromProps(props, state) {
const { value, minValue, maxValue, defaultValue } = props

const validatedValue = validateValue(
const validatedValue = validateValue({
value,
minValue,
maxValue,
defaultValue
)
min: minValue,
max: maxValue,
defaultValue,
})

return {
value: validatedValue,
Expand Down Expand Up @@ -111,15 +112,15 @@ class NumericStepper extends Component {
displayValue,
})

if (this.state.value !== validatedValue && onChange) {
// React synthetic events are reused for performance reasons.
// New properties added to it are never released.
// Calling event.persist() releases the event from the pool
// https://reactjs.org/docs/events.html#event-pooling
event.persist()
event.value = validatedValue
onChange(event)
}
if (this.state.value === validatedValue || !onChange) return

// React synthetic events are reused for performance reasons.
// New properties added to it are never released.
// Calling event.persist() releases the event from the pool
// https://reactjs.org/docs/events.html#event-pooling
event.persist()
event.value = validatedValue
onChange(event)
}

handleTypeQuantity = event => {
Expand Down
3 changes: 3 additions & 0 deletions react/components/Radio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Radio extends PureComponent {
})}
ref={this.container}
onClick={this.handleContainerClick}
role="button"
tabIndex="0"
onKeyPress={() => null}
>
{/* This empty div is used so that the radio circle is not a direct child of
* a flex element, and thus can set a fixed width. Otherwise, the width would
Expand Down
1 change: 1 addition & 0 deletions react/components/RadioGroup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class RadioGroup extends React.Component {
borderBottomRightRadius: 0,
}),
}}
htmlFor={id}
>
<div className={classNames({ mt3: !hideBorder })}>
<Radio
Expand Down