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

[Menu] Add prop to disable auto focus #11984

Merged
merged 3 commits into from
Jun 26, 2018
Merged
Changes from 1 commit
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
Next Next commit
Added Menu prop to disable auto focus
th317erd authored and oliviertassinari committed Jun 26, 2018
commit c23807742caffb4a3693adc96db1ec3af79aa6cf
12 changes: 9 additions & 3 deletions packages/material-ui/src/Menu/Menu.js
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ class Menu extends React.Component {
menuList = null;

componentDidMount() {
if (this.props.open) {
if (this.props.open && this.props.disableAutoFocus !== true) {
this.focus();
}
}
@@ -63,7 +63,9 @@ class Menu extends React.Component {
const menuList = ReactDOM.findDOMNode(this.menuList);

// Focus so the scroll computation of the Popover works as expected.
this.focus();
if (this.props.disableAutoFocus !== true) {
this.focus();
}

// Let's ignore that piece of logic if users are already overriding the width
// of the menu.
@@ -146,6 +148,10 @@ Menu.propTypes = {
* See [CSS API](#css-api) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* If `true`, the first menu item will not be auto focused.
*/
disableAutoFocus: PropTypes.bool,
/**
* Properties applied to the `MenuList` element.
*/
@@ -203,7 +209,7 @@ Menu.propTypes = {
PropTypes.number,
PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number }),
PropTypes.oneOf(['auto']),
]),
])
};

Menu.defaultProps = {