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

[core] Reduce calls to actions prop #15370

Merged
merged 1 commit into from
Apr 16, 2019
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
64 changes: 34 additions & 30 deletions packages/material-ui/src/MenuList/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,41 @@ const MenuList = React.forwardRef(function MenuList(props, ref) {
const listRef = React.useRef();
const selectedItemRef = React.useRef();

React.useImperativeHandle(actions, () => ({
focus: () => {
if (selectedItemRef.current) {
selectedItemRef.current.focus();
return;
}
React.useImperativeHandle(
actions,
() => ({
focus: () => {
if (selectedItemRef.current) {
selectedItemRef.current.focus();
return;
}

if (listRef.current && listRef.current.firstChild) {
listRef.current.firstChild.focus();
}
},
getContentAnchorEl: () => {
if (selectedItemRef.current) {
return selectedItemRef.current;
}
return listRef.current.firstChild;
},
adjustStyleForScrollbar: (containerElement, theme) => {
// Let's ignore that piece of logic if users are already overriding the width
// of the menu.
const noExplicitWidth = !listRef.current.style.width;
if (containerElement.clientHeight < listRef.current.clientHeight && noExplicitWidth) {
const scrollbarSize = `${getScrollbarSize(true)}px`;
listRef.current.style[
theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight'
] = scrollbarSize;
listRef.current.style.width = `calc(100% + ${scrollbarSize})`;
}
return listRef.current;
},
}));
if (listRef.current && listRef.current.firstChild) {
listRef.current.firstChild.focus();
}
},
getContentAnchorEl: () => {
if (selectedItemRef.current) {
return selectedItemRef.current;
}
return listRef.current.firstChild;
},
adjustStyleForScrollbar: (containerElement, theme) => {
// Let's ignore that piece of logic if users are already overriding the width
// of the menu.
const noExplicitWidth = !listRef.current.style.width;
if (containerElement.clientHeight < listRef.current.clientHeight && noExplicitWidth) {
const scrollbarSize = `${getScrollbarSize(true)}px`;
listRef.current.style[
theme.direction === 'rtl' ? 'paddingLeft' : 'paddingRight'
] = scrollbarSize;
listRef.current.style.width = `calc(100% + ${scrollbarSize})`;
}
return listRef.current;
},
}),
[],
);

React.useEffect(() => {
resetTabIndex(listRef.current, selectedItemRef.current, setCurrentTabIndex);
Expand Down
26 changes: 15 additions & 11 deletions packages/material-ui/src/RadioGroup/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ const RadioGroup = React.forwardRef(function RadioGroup(props, ref) {
return null;
});

React.useImperativeHandle(actions, () => ({
focus: () => {
let input = rootRef.current.querySelector('input:not(:disabled):checked');
React.useImperativeHandle(
actions,
() => ({
focus: () => {
let input = rootRef.current.querySelector('input:not(:disabled):checked');

if (!input) {
input = rootRef.current.querySelector('input:not(:disabled)');
}
if (!input) {
input = rootRef.current.querySelector('input:not(:disabled)');
}

if (input) {
input.focus();
}
},
}));
if (input) {
input.focus();
}
},
}),
[],
);

React.useEffect(() => {
warning(
Expand Down