Skip to content

Commit

Permalink
[Select] Fix validator.w3.org error (#20356)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfsjr authored Apr 1, 2020
1 parent 151834f commit c253b28
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/src/pages/components/selects/MultipleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default function MultipleSelect() {
return selected.join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem disabled value="">
<em>Placeholder</em>
Expand Down
1 change: 1 addition & 0 deletions docs/src/pages/components/selects/MultipleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default function MultipleSelect() {
return (selected as string[]).join(', ');
}}
MenuProps={MenuProps}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem disabled value="">
<em>Placeholder</em>
Expand Down
16 changes: 14 additions & 2 deletions docs/src/pages/components/selects/SimpleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export default function SimpleSelect() {
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<Select value={age} onChange={handleChange} displayEmpty className={classes.selectEmpty}>
<Select
value={age}
onChange={handleChange}
displayEmpty
className={classes.selectEmpty}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
Expand Down Expand Up @@ -160,7 +166,13 @@ export default function SimpleSelect() {
<FormHelperText>Auto width</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<Select value={age} onChange={handleChange} displayEmpty className={classes.selectEmpty}>
<Select
value={age}
onChange={handleChange}
displayEmpty
className={classes.selectEmpty}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="" disabled>
Placeholder
</MenuItem>
Expand Down
16 changes: 14 additions & 2 deletions docs/src/pages/components/selects/SimpleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export default function SimpleSelect() {
<FormHelperText>Some important helper text</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<Select value={age} onChange={handleChange} displayEmpty className={classes.selectEmpty}>
<Select
value={age}
onChange={handleChange}
displayEmpty
className={classes.selectEmpty}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
Expand Down Expand Up @@ -162,7 +168,13 @@ export default function SimpleSelect() {
<FormHelperText>Auto width</FormHelperText>
</FormControl>
<FormControl className={classes.formControl}>
<Select value={age} onChange={handleChange} displayEmpty className={classes.selectEmpty}>
<Select
value={age}
onChange={handleChange}
displayEmpty
className={classes.selectEmpty}
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="" disabled>
Placeholder
</MenuItem>
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,15 @@ describe('<Select />', () => {
const { getByRole } = render(<Select value="" />);

// TODO what is the accessible name actually?
expect(getByRole('button')).to.have.attribute('aria-labelledby', ' ');
expect(getByRole('button')).to.not.have.attribute('aria-labelledby');
});

it('is labelled by itself when it has a name', () => {
const { getByRole } = render(<Select name="select" value="" />);

expect(getByRole('button')).to.have.attribute(
'aria-labelledby',
` ${getByRole('button').getAttribute('id')}`,
getByRole('button').getAttribute('id'),
);
});

Expand Down
8 changes: 7 additions & 1 deletion packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function isEmpty(display) {
*/
const SelectInput = React.forwardRef(function SelectInput(props, ref) {
const {
'aria-label': ariaLabel,
autoFocus,
autoWidth,
children,
Expand Down Expand Up @@ -324,8 +325,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
tabIndex={tabIndex}
role="button"
aria-expanded={open ? 'true' : undefined}
aria-labelledby={`${labelId || ''} ${buttonId || ''}`}
aria-haspopup="listbox"
aria-label={ariaLabel}
aria-labelledby={[labelId, buttonId].filter(Boolean).join(' ') || undefined}
onKeyDown={handleKeyDown}
onMouseDown={disabled || readOnly ? null : handleMouseDown}
onBlur={handleBlur}
Expand Down Expand Up @@ -383,6 +385,10 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
});

SelectInput.propTypes = {
/**
* @ignore
*/
'aria-label': PropTypes.string,
/**
* @ignore
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/TablePagination/TablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const styles = (theme) => ({
caption: {
flexShrink: 0,
},
// TODO v5: `.selectRoot` should be merged with `.input`
/* Styles applied to the Select component root element. */
selectRoot: {
// `.selectRoot` should be merged with `.input` in v5.
marginRight: 32,
marginLeft: 8,
},
Expand Down Expand Up @@ -122,6 +122,7 @@ const TablePagination = React.forwardRef(function TablePagination(props, ref) {
input={<InputBase className={clsx(classes.input, classes.selectRoot)} />}
value={rowsPerPage}
onChange={onChangeRowsPerPage}
inputProps={{ 'aria-label': labelRowsPerPage }}
{...SelectProps}
>
{rowsPerPageOptions.map((rowsPerPageOption) => (
Expand Down

0 comments on commit c253b28

Please sign in to comment.