Skip to content

Commit

Permalink
Merge pull request #134 from ChildishGiant/select-active-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRuf authored Aug 15, 2021
2 parents 003b840 + 073e1ca commit 10c81ba
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
5 changes: 4 additions & 1 deletion js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@
this.focusedIndex < this.dropdownEl.children.length &&
this.options.autoFocus
) {
this.dropdownEl.children[this.focusedIndex].classList.add('active');
this.dropdownEl.children[this.focusedIndex].focus({
preventScroll: true
});
this.dropdownEl.children[this.focusedIndex].scrollIntoView({
behavior: 'smooth',
block: 'nearest',
Expand Down Expand Up @@ -621,6 +623,7 @@
if (!this.isOpen) {
return;
}

this.isOpen = false;
this.focusedIndex = -1;

Expand Down
94 changes: 94 additions & 0 deletions test/html/select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"/>
<title>Select testbed</title>
<!-- CSS -->
<link href="../../../bin/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>

<style>
body {
padding: 16px;
}
.input-field{
padding-bottom: 2em;
}
</style>
</head>
<body>

<div class="input-field col s12">
<select>
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>
</div>

<div class="input-field col s12">
<select multiple>
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Multiple Select</label>
</div>

<div class="input-field col s12">
<select>
<optgroup label="team 1">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</optgroup>
<optgroup label="team 2">
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</optgroup>
</select>
<label>Optgroups</label>
</div>

<div class="input-field col s12 m6">
<select class="icons">
<option value="" disabled selected>Choose your option</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_a.png">example 1</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_b.png">example 2</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_c.png">example 3</option>
</select>
<label>Images in select</label>
</div>
<div class="input-field col s12 m6">
<select class="icons">
<option value="" disabled selected>Choose your option</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_a.png" class="left">example 1</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_b.png" class="left">example 2</option>
<option value="" data-icon="../../docs/images/placeholder/250x250_c.png" class="left">example 3</option>
</select>
<label>Images in select</label>
</div>

<label>Browser Select</label>
<select class="browser-default">
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>


<script src="../../../bin/materialize.js"></script>

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems, {
// specify options here
});
});
</script>
</body>
</html>

0 comments on commit 10c81ba

Please sign in to comment.