Skip to content

Commit

Permalink
[Autocomplete] Follow Material Design State spec (#23323)
Browse files Browse the repository at this point in the history
  • Loading branch information
sujinleeme authored Oct 31, 2020
1 parent b34bee7 commit d690483
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
33 changes: 27 additions & 6 deletions packages/material-ui/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { withStyles } from '../styles';
import { alpha } from '../styles/colorManipulator';
import Popper from '../Popper';
import ListSubheader from '../ListSubheader';
import Paper from '../Paper';
Expand Down Expand Up @@ -205,19 +206,39 @@ export const styles = (theme) => ({
[theme.breakpoints.up('sm')]: {
minHeight: 'auto',
},
'&[aria-selected="true"]': {
backgroundColor: theme.palette.action.selected,
},
'&[data-focus="true"]': {
backgroundColor: theme.palette.action.hover,
},
'&:active': {
backgroundColor: theme.palette.action.selected,
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
'&[aria-disabled="true"]': {
opacity: theme.palette.action.disabledOpacity,
pointerEvents: 'none',
},
'&.Mui-focusVisible': {
backgroundColor: theme.palette.action.focus,
},
'&[aria-selected="true"]': {
backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
'&[data-focus="true"]': {
backgroundColor: alpha(
theme.palette.primary.main,
theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity,
),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: theme.palette.action.selected,
},
},
'&.Mui-focusVisible': {
backgroundColor: alpha(
theme.palette.primary.main,
theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity,
),
},
},
},
/* Styles applied to the group's label elements. */
groupLabel: {
Expand Down
9 changes: 5 additions & 4 deletions packages/material-ui/src/PaginationItem/PaginationItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { alpha, useTheme, withStyles, useThemeVariants } from '../styles';
import { useTheme, withStyles, useThemeVariants } from '../styles';
import { alpha } from '../styles/colorManipulator';
import ButtonBase from '../ButtonBase';
import { capitalize } from '../utils';
import FirstPageIcon from '../internal/svg-icons/FirstPage';
Expand Down Expand Up @@ -34,6 +35,9 @@ export const styles = (theme) => ({
backgroundColor: 'transparent',
},
},
'&$disabled': {
opacity: theme.palette.action.disabledOpacity,
},
'&$focusVisible': {
backgroundColor: theme.palette.action.focus,
},
Expand Down Expand Up @@ -61,9 +65,6 @@ export const styles = (theme) => ({
backgroundColor: theme.palette.action.selected,
},
},
'&$disabled': {
opacity: theme.palette.action.disabledOpacity,
},
},
/* Styles applied applied to the root element if `size="small"`. */
sizeSmall: {
Expand Down
4 changes: 4 additions & 0 deletions packages/material-ui/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export default function useAutocomplete(props) {
const prev = listboxRef.current.querySelector('[data-focus]');
if (prev) {
prev.removeAttribute('data-focus');
prev.classList.remove('Mui-focusVisible');
}

const listboxNode = listboxRef.current.parentElement.querySelector('[role="listbox"]');
Expand All @@ -320,6 +321,9 @@ export default function useAutocomplete(props) {
}

option.setAttribute('data-focus', 'true');
if (reason === 'keyboard') {
option.classList.add('Mui-focusVisible');
}

// Scroll active descendant into view.
// Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
Expand Down

0 comments on commit d690483

Please sign in to comment.