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

feat(Dropdown, DropdownMenu, DropdownToggle): allow Dropdown to have … #2077

Conversation

andyseracuse
Copy link
Contributor

@andyseracuse andyseracuse commented Jan 15, 2021

…listbox or menu role

Dropdown Menu should allow for listbox or menu roles. Before this commit, the Dropdown could only have the menu role. After this commit, a user can add a menuRole property to the Dropdown component which will set a corresponding aria-haspopop property on the DropdownToggle, role property on the DropdownMenu, and role property on the Dropdown Items

  • Bug fix
  • New feature
  • Chore
  • Breaking change
  • There is an open issue which this change addresses
  • I have read the CONTRIBUTING document.
  • My commits follow the Git Commit Guidelines
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • My change requires a change to Typescript typings.
    • I have updated the typings accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…listbox or menu role

Dropdown Menu should allow for listbox or menu roles.  Before this commit, the Dropdown could only have the menu role.  After this commit, a user can add a menuRole property to the Dropdown component which will set a corresponding aria-haspopop property on the DropdownToggle, role property on the DropdownMenu, and role property on the Dropdown Items
src/DropdownToggle.js Outdated Show resolved Hide resolved
src/Dropdown.js Outdated Show resolved Hide resolved
src/Dropdown.js Outdated Show resolved Hide resolved
src/Dropdown.js Outdated Show resolved Hide resolved
src/DropdownMenu.js Outdated Show resolved Hide resolved
src/Dropdown.js Outdated
@@ -35,7 +36,8 @@ const defaultProps = {
active: false,
addonType: false,
inNavbar: false,
setActiveFromChild: false
setActiveFromChild: false,
menuRole: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this. Just to make this behavior opt-in

src/DropdownToggle.js Outdated Show resolved Hide resolved
Address all code cleanlieness and backwards compatibility issues brought up in PR
@andyseracuse
Copy link
Contributor Author

Okay! I made all the suggested changes. Thanks so much for all your suggestions and guidance @kyletsang

Copy link
Member

@kyletsang kyletsang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Few more nitpicks and we're good to go.

src/Dropdown.js Outdated
if(this.context.menuRole === 'listbox') {
return 'option'
}
return 'menu'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 'menu'
return 'menuitem'

src/Dropdown.js Outdated
Comment on lines 124 to 127
if(this.context.menuRole) {
return [].slice.call(menuContainer.querySelectorAll('[role="' + this.getItemType() + '"]'));
}
return [].slice.call(menuContainer.querySelectorAll('[role="menuitem"]'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(this.context.menuRole) {
return [].slice.call(menuContainer.querySelectorAll('[role="' + this.getItemType() + '"]'));
}
return [].slice.call(menuContainer.querySelectorAll('[role="menuitem"]'));
return [].slice.call(menuContainer.querySelectorAll(`[role="${this.getItemType()}"]`));

getItemType will return the default menuitem in case when menuRole doesn't exist, so we can simplify this. Also, string interpolation is good to use here too

Comment on lines 35 to 41
const menuRole = this.context.menuRole
if(menuRole === true || menuRole === 'menu' || menuRole === undefined) {
return 'menuitem'
}
if(menuRole === 'listbox') {
return 'option'
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify this function similar to getRole in DropdownMenu

render() {
console.log(this.getRole())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(this.getRole())

@andyseracuse
Copy link
Contributor Author

gotcha, I'm on it! Thanks so much for all your help. This has been super educational!!!

… and fix a typo

Address all issues mentioned in PR review
@kyletsang
Copy link
Member

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants