-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
[Bug]: tabindex properties on select elements are destroyed during initialization #510
Comments
Note my workaound above also fails in v2.1.1 because of some differences in how the elements are constructed in the _SetupDropdown method. |
I've created a workarond that works in v2.1.1. Again, this depends on setting the tabIndex property on the label for the select element.... document.addEventListener('DOMContentLoaded', function() { var selElems = document.querySelectorAll('select'); var selInstances = M.FormSelect.init(selElems, { // specify options here }); selInstances.forEach(setSelectTab); } function setSelectTab(selInstance) { if (selInstance.labelEl.tabIndex > 0) { selInstance.input.tabIndex = selInstance.labelEl.tabIndex; selInstance.labelEl.tabIndex = -1; } } |
It turns out accessibility is currently a major issue in Materialize as it does affects multiple components I'll create a new issue for the follow up of all accessibility related issues and will reference this issue regarding the select component |
@cmorgancli |
It would also be great if you can provide a Codepen example of your usecase and additional screenshots explaining the issue in more detail, as it would me more accurate to reproduce |
@gselderslaghs My current workaround is not a change to any materialize code. I am post-processing the dom after initialization with the javascript I included in my comment. I will look at creating a PR that fixes the issue in the materialize code. |
Before submitting...
Context
The _SetupDropdown method that gets run when the select is initialized sets the tabIndex property on the original select element to -1, but does not set any tabIndex property on the text input element that it creates. The end result is that any form that contains select elements can not have a predefined tab order.
Current Behavior
It is impossible to set a specific tab order for select elements
Expected behavior
It should be possible to specify a tabIndex property on a select element and have that property applied to the input element created during initialization.
Possible Solutions or Causes
I think this is a relatively easy issue to fix in the _SetupDropdown method. Just set the tabIndex property on the input element to match the value on the original select element.
Steps to reproduce
Create any page containing a form with a select element.
View the DOM and observe that there is no tabIndex property on the input element created during initialization.
Your Environment
I created a kludgy workaound by adding a tabIndex property to the label on the select element, and then running this javascript after initialization:
var labelEls = document.getElementsByTagName("label"); for (i=0; i < labelEls.length; i++) { if (labelEls[i].id.startsWith('m_select')) { if (labelEls[i].tabIndex > 0) { //console.log( labelEls[i].htmlFor + ' tabindex ' + labelEls[i].tabIndex ); document.getElementById(labelEls[i].htmlFor).tabIndex = labelEls[i].tabIndex; labelEls[i].tabIndex = -1; } } }
The text was updated successfully, but these errors were encountered: