Skip to content

[DropDownMenu][SelectField] Add Keyboard support#4966

Closed
caesay wants to merge 14 commits intomui:masterfrom
FignumOld:BL-1292
Closed

[DropDownMenu][SelectField] Add Keyboard support#4966
caesay wants to merge 14 commits intomui:masterfrom
FignumOld:BL-1292

Conversation

@caesay
Copy link

@caesay caesay commented Aug 11, 2016

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

This adds keyboard support natively to DropDownMenu, and also SelectField by extension.

This (I think) is a better option than this pull request because it adds the keyboard support to all DropDownMenu's instead of SelectField.

DropDownMenu now has an IconButton that can receive (and indicate) focus. space or down arrow will open the drop down, and enter or esc will close the drop down.

@caesay caesay changed the title [DropDownMenu, SelectField] Add Keyboard support [DropDownMenu][SelectField] Add Keyboard support Aug 11, 2016
@petermikitsh
Copy link
Contributor

This PR is different from #4871 in that it highlights the arrow on tab:

screen shot 2016-08-11 at 5 06 40 pm

Versus #4871:

I wasn't able to find a material spec for this, but it is a notable difference between the two. Personally, I prefer the animation in #4871.

@caesay
Copy link
Author

caesay commented Aug 12, 2016

@petermikitsh The animation here can be changed to include the textbox underline, that's not a big deal. The big deal is that this also adds keyboard support to DropDownMenu's that are NOT inside of a SelectField as well. Go to /#/components/dropdown-menu to see that it still works there, where #4871 doesn't.

@petermikitsh
Copy link
Contributor

I get the technical benefits to this PR, but I visually prefer #4871. Maybe we could get the best of both worlds and combine the two?

@caesay
Copy link
Author

caesay commented Aug 12, 2016

@petermikitsh in DropDownMenu.js line 234 and 238 - that's the reason the TextField doesn't recieve focus events.. I was trying to get it to work so it would underline the textbox at first, but when TextField gets a focus or blur event it does a setState, which re-renders its children and causes the drop down to lose focus. I couldn't get it to work that way but agree that it would be optimal. Do you want to take a look at this? just comment those lines and you'll see what i mean.

@petermikitsh
Copy link
Contributor

Yeah, lines 234 and 238 prevent TextField from receiving events. That's why I implemented a new prop, onClose, that can be passed into DropDownMenu. The SelectField passes in this function to DropDownMenu, which focuses the TextField component.

@caesay
Copy link
Author

caesay commented Aug 12, 2016

@petermikitsh Right, i re-focus on the drop down close too (inside of DropDownMenu instead) but a new prop doesn't fix anything if you're focusing the DropDownMenu instead of the TextField (which is what should happen). If you focus the DropDownMenu again TextBox still re-renders and the focus ends in no-where-land. The only reason #4871 works with an extra prop is because the TextBox holds the focus and not the DropDownMenu and that's the whole problem I have with that pull.

Both pull's have problems, and I don't care which gets accepted, but IMO the right solution is finding a way to handle focus events in DropDownMenu, and bubble the events up to TextField without screwing up the active element.

@petermikitsh
Copy link
Contributor

petermikitsh commented Aug 12, 2016

Probably a dumb question, but why is there both a DropDownMenu and SelectField?

http://www.material-ui.com/#/components/dropdown-menu
http://www.material-ui.com/#/components/select-field

They seem visually and functionally identical.

<DropDownMenu value={this.state.value} onChange={this.handleChange}>
  <MenuItem value={1} primaryText="Never" />
  <MenuItem value={2} primaryText="Every Night" />
  <MenuItem value={3} primaryText="Weeknights" />
  <MenuItem value={4} primaryText="Weekends" />
  <MenuItem value={5} primaryText="Weekly" />
</DropDownMenu>
<SelectField value={this.state.value} onChange={this.handleChange}>
  <MenuItem value={1} primaryText="Never" />
  <MenuItem value={2} primaryText="Every Night" />
  <MenuItem value={3} primaryText="Weeknights" />
  <MenuItem value={4} primaryText="Weekends" />
  <MenuItem value={5} primaryText="Weekly" />
</SelectField>

@caesay
Copy link
Author

caesay commented Aug 12, 2016

@petermikitsh DropDownMenu has a wider use-case than SelectField. DropDownMenu could, for instance, be a drop down of links that upon click direct you to different pages. SelectField is for form input where the user can change the selected value (which is not necessarily true of DropDownMenu).

DropDownMenu is important, especially for writing your own components with custom function as SelectField is locked into the purpose of being an input essentially.

@caesay
Copy link
Author

caesay commented Aug 12, 2016

I don't know why this is a debate. Clearly #4871 breaks the re-usability of DropDownMenu, and for what? a different visual style?

@petermikitsh
Copy link
Contributor

Does #4871 break DropDownMenu functionally?

@petermikitsh
Copy link
Contributor

Give me a second, I'm making more changes.

@caesay
Copy link
Author

caesay commented Aug 12, 2016

It doesn't break what's already there, but accessibility of DropDownMenu and SelectField has been on the issue tracker for a while and #4871 will need to be reverted if keyboard support is ever to be added to DropDownMenu and that doesn't make sense since this pull already addresses both components.

@petermikitsh
Copy link
Contributor

#4871 will need to be reverted if keyboard support is ever to be added to DropDownMenu

I just merged our two branches and that seems to not be the case.

@petermikitsh
Copy link
Contributor

For sake of parity, I can support this change set over #4871.

@nathanmarks
Copy link
Contributor

@petermikitsh @caesay

Don't worry too much about the future because there is a semi-rewrite coming up in the next few months. The semi-rewrite is being done with not just keyboard accessibility in mind, but I am also testing every single component with a screen reader.

@caesay
Copy link
Author

caesay commented Aug 19, 2016

@petermikitsh If you check I've fixed the visual style so that it underlines the textbox as well how you like!

@nathanmarks So does that mean this won't get accepted? should I also open a pull request that adds keyboard support to the DatePicker component or is it the same situation there?

@nathanmarks
Copy link
Contributor

@caesay they'll definitely still be accepted, there is another breaking release coming for master now. I'm just saying don't invest too much time worrying about making things absolutely perfect as this code will not stay in the long term.

Underlying components such as Menu and TextField are being completely rewritten. There are a lot of problems in the current version of MUI that are very difficult to fix incrementally. In next, the keyboard accessibility features are built into Menu itself.

In addition to fixing keyboard accessibility for menus, I've also added in a critical UX feature that we are currently missing: opening menus to the currently selected item.

@JeffreyATW
Copy link

JeffreyATW commented Sep 9, 2016

@nathanmarks is the breaking change part of the next branch? I'm looking to enable keyboard navigation within this component and would much prefer that this go in and then get overridden when next is ready for prime time. Who needs to review this so that it can be merged into master?

@JeffreyATW
Copy link

I decided to go ahead and review it myself, and found a number of problems with my controlled component, evidenced by this GIF:

sep-09-2016 11-00-55

  1. The dropdown arrow has changed color from light gray to black.
  2. When activating the dropdown, onChange seems to be fired, because my error validation immediately kicks in.
  3. Tabbing away clears the field. I'm pretty sure the field should never be cleared.

@tuchk4
Copy link

tuchk4 commented Oct 6, 2016

@petermikitsh you closed PR#4871 in favor of this. But there is useful feature at that PR - onClose prop for DropDown component. It would be prefect to save it.

@muibot muibot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: Needs Review labels Nov 26, 2016
@mbrookes mbrookes added component: DropDownMenu scope: select Changes related to the select. labels Jan 2, 2017
@patrickml
Copy link

Did this ever make it into a release?

@eL-HaXo
Copy link

eL-HaXo commented Jan 12, 2017

I'd like to know if this is going to be released as well. The ability to tab to a select field when filling out a form is a necessity for my project. If this will not be released I'll take a stab at implementing it myself and will submit a PR.

Here is a bug for the issue: #5498

@gmacciocca
Copy link

My project also would benefit greatly form this PR.

@oliviertassinari
Copy link
Member

I have opened #5921 to bring this PR into master. Any feedback is welcomed 🙏 .

@oliviertassinari oliviertassinari added on hold There is a blocker, we need to wait. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. PR: Needs Review labels Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on hold There is a blocker, we need to wait. scope: select Changes related to the select.

Projects

None yet

Development

Successfully merging this pull request may close these issues.