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

[Select] Fix validator.w3.org error #20356

Merged
merged 7 commits into from
Apr 1, 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
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 @@ -320,8 +321,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 @@ -379,6 +381,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