| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -17,6 +17,9 @@ const propTypes = { | |
| isOpen: PropTypes.bool, | ||
| /** Flag to indicate if menu should be opened on enter */ | ||
| openedOnEnter: PropTypes.bool, | ||
| /** Flag to indicate if the first dropdown item should gain initial focus, set false when adding | ||
| * a specific auto-focus item (like a current selection) otherwise leave as true */ | ||
| autoFocus: PropTypes.bool, | ||
| /** Indicates which component will be used as dropdown menu */ | ||
| component: componentShape, | ||
| /** Indicates where menu will be alligned horizontally */ | ||
| Expand All | @@ -32,6 +35,7 @@ const defaultProps = { | |
| className: '', | ||
| isOpen: true, | ||
| openedOnEnter: false, | ||
| autoFocus: true, | ||
| position: DropdownPosition.left, | ||
| component: 'ul', | ||
| isGrouped: false | ||
| Expand All | @@ -41,14 +45,18 @@ class DropdownMenu extends React.Component { | |
| refsCollection = []; | ||
|
|
||
| componentDidMount() { | ||
| const focusTarget = | ||
| this.refsCollection.filter( | ||
| ref => ref && ((ref.current && !ref.current.hasAttribute('disabled')) || !ref.hasAttribute('disabled')) | ||
| )[0] || null; | ||
| if (this.props.component === 'ul') focusTarget && focusTarget.focus(); | ||
| else { | ||
| (focusTarget.current.focus && focusTarget.current.focus()) || | ||
| (focusTarget && ReactDOM.findDOMNode(focusTarget.current).focus()); // eslint-disable-line react/no-find-dom-node | ||
| const { autoFocus } = this.props; | ||
|
|
||
| if (this.props.component === 'ul' && autoFocus) { | ||
| const focusTarget = | ||
| this.refsCollection.filter( | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality.find() is equivalent to .filter()[0].
Sorry, something went wrong.
All reactions
|
||
| ref => ref && ((ref.current && !ref.current.hasAttribute('disabled')) || !ref.hasAttribute('disabled')) | ||
| )[0] || null; | ||
| if (this.props.component === 'ul') focusTarget && focusTarget.focus(); | ||
| else { | ||
| (focusTarget.current.focus && focusTarget.current.focus()) || | ||
| (focusTarget && ReactDOM.findDOMNode(focusTarget.current).focus()); // eslint-disable-line react/no-find-dom-node | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCould also destructure component.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.