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

[Autocomplete] Apply .Mui-focused instead of data-focus on the focused option #26181

Merged
merged 2 commits into from
May 12, 2021
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: 7 additions & 0 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ As the core components use emotion as a styled engine, the props used by emotion
2. `select-option` to `selectOption`
3. `remove-option` to `removeOption`

- Change the CSS rules that use `[data-focus="true"]` to use `.Mui-focused`. The `data-focus` attribute is not set on the focused option anymore, instead, global class names are used.

```diff
-'.MuiAutocomplete-option[data-focus="true"]': {
+'.MuiAutocomplete-option.Mui-focused': {
```

### Avatar

- Rename `circle` to `circular` for consistency. The possible values should be adjectives, not nouns:
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const AutocompleteListbox = experimentalStyled(
[theme.breakpoints.up('sm')]: {
minHeight: 'auto',
},
'&[data-focus="true"]': {
[`&.${autocompleteClasses.focused}`]: {
backgroundColor: theme.palette.action.hover,
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
Expand All @@ -354,7 +354,7 @@ const AutocompleteListbox = experimentalStyled(
},
'&[aria-selected="true"]': {
backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
'&[data-focus="true"]': {
[`&.${autocompleteClasses.focused}`]: {
backgroundColor: alpha(
theme.palette.primary.main,
theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity,
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Autocomplete, {
} from '@material-ui/core/Autocomplete';

function checkHighlightIs(listbox, expected) {
const focused = listbox.querySelector('[role="option"][data-focus]');
const focused = listbox.querySelector(`.${classes.focused}`);

if (expected) {
if (focused) {
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ export default function useAutocomplete(props) {
return;
}

const prev = listboxRef.current.querySelector('[data-focus]');
const prev = listboxRef.current.querySelector('[role="option"].Mui-focused');
if (prev) {
prev.removeAttribute('data-focus');
prev.classList.remove('Mui-focused');
prev.classList.remove('Mui-focusVisible');
}

Expand All @@ -320,7 +320,7 @@ export default function useAutocomplete(props) {
return;
}

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