toggle 'active' class on prefix icon for select
Expected Behavior
When opening/closing the select dropdown, the class "active" should be toggled on the prefix icon. This will make the prefix icon consistent with other inputs.
Current Behavior
It doesn't toggle the active class on the .prefix element so there's no change in style.
Possible Solution
Toggle the active class on the .prefix element on click of the select input. Also, it would be nice to have active class toggled on the select wrapper as well so that people can target it for styling.
I'm fairly new to MaterializeCSS, so please forgive me if i'm incorrect about certain things.
After examining select.js, I believe all that is needed is to add the following line to beginning of _handleInputClick():
$(this.wrapper).prevAll("i.prefix").toggleClass('active');
// also if you can, toggle active class on select wrapper
$(this.wrapper).toggleClass('active');
There doesn't seem to be any class that's added to the input, ul, wrapper, or any element when the select is open, therefore I cannot use css to style it.
Steps to Reproduce
Example:
<div class="input-field">
<i class="material-icons prefix">account_circle</i>
<select>
<option value="1">option1</option>
<option value="2">option2</option>
</select>
<label>Choose an option:</label>
</div>
// onReady
$('select').formSelect();
Environment
- Version used: "^1.0.0-beta"
- Browser Name and version: Google Chrome 67.0.3396.87 (Official Build) (64-bit)
- Operating System and version (desktop or mobile): Windows 10 home 64-bit
Other Information
I also commented on this other related issue that was closed about a year ago.
Thank you for your time and patience :)
My current workaround to get the select to behave correctly:
var $selectboxes = $('select').formSelect();
$selectboxes.each((index) => {
var self = M.FormSelect.getInstance($selectboxes[index]);
$(self.input).focus(() => {
$(self.wrapper).prevAll("i.prefix").addClass('active');
});
$(self.dropdownOptions).focus(() => {
$(self.wrapper).prevAll("i.prefix").addClass('active');
});
$(self.input).focusout(() => {
$(self.wrapper).prevAll("i.prefix").removeClass('active');
});
});
Although, for some reason, when I click outside of the dropdown to close it (say on another input) focus is returned to the input instead of where I clicked. This seems to be an issue with dropdown though where it should only return focus to .dropdown-trigger iff the user clicked inside the dropdown menu.