-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(select): Add new UX styles and behavior to select #1097
Changes from 34 commits
5e244b7
570f1fd
226ad9e
b4b46f1
3cda334
274343b
257238f
c185392
cbb0bf5
f0319c9
1f0ae99
28a8c11
689cf23
14bf9a6
845576e
98ef434
d52cb82
fb7e70b
2314b5f
b9d0baf
661708b
b0dc987
6121632
b611d17
a08578b
5bc86c6
84a4108
1a68a35
65ff407
7b819aa
9a8abe8
40d5442
d9ef1df
c932e62
a5fdc64
9b6553d
1063e6d
4d1ba25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
} | ||
|
||
.example { | ||
max-width: 400px; | ||
margin: 24px; | ||
padding: 24px; | ||
} | ||
|
@@ -65,12 +66,13 @@ | |
<div class="mdc-toolbar-fixed-adjust"></div> | ||
<section class="hero"> | ||
<div id="hero-js-select" class="mdc-select" role="listbox" tabindex="0"> | ||
<span class="mdc-select__selected-text">Pick a food group</span> | ||
<div class="mdc-select__surface"> | ||
<div class="mdc-select__label">Pick a Food Group</div> | ||
<div class="mdc-select__selected-text"></div> | ||
<div class="mdc-select__bottom-line"></div> | ||
</div> | ||
<div class="mdc-simple-menu mdc-select__menu"> | ||
<ul class="mdc-list mdc-simple-menu__items"> | ||
<li class="mdc-list-item" role="option" aria-disabled="true"> | ||
Pick a food group | ||
</li> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Bread, Cereal, Rice, and Pasta | ||
</li> | ||
|
@@ -80,7 +82,7 @@ | |
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Fruit | ||
</li> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Milk, Yogurt, and Cheese | ||
</li> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
|
@@ -96,37 +98,29 @@ | |
|
||
<section class="example"> | ||
<h2 class="mdc-typography--title">Fully-Featured Component</h2> | ||
<section id="demo-wrapper"> | ||
<div id="js-select" class="mdc-select" role="listbox" tabindex="0"> | ||
<span class="mdc-select__selected-text">Pick a food group</span> | ||
<section id="box-demo-wrapper"> | ||
<div id="js-select-box" class="mdc-select" role="listbox" tabindex="0"> | ||
<div class="mdc-select__surface"> | ||
<div class="mdc-select__label">Food Group</div> | ||
<div class="mdc-select__selected-text"></div> | ||
<div class="mdc-select__bottom-line"></div> | ||
</div> | ||
<div class="mdc-simple-menu mdc-select__menu"> | ||
<ul class="mdc-list mdc-simple-menu__items"> | ||
<li class="mdc-list-item" role="option" id="grains" aria-disabled="true"> | ||
Pick a food group | ||
<li class="mdc-list-item" role="option" id="fruit-roll-ups" tabindex="0"> | ||
Fruit Roll Ups | ||
</li> | ||
<li class="mdc-list-item" role="option" id="grains" tabindex="0"> | ||
Bread, Cereal, Rice, and Pasta | ||
<li class="mdc-list-item" role="option" id="cotton-candy" tabindex="0"> | ||
Candy (cotton) | ||
</li> | ||
<li class="mdc-list-item" role="option" id="vegetables" aria-disabled="true" tabindex="0"> | ||
Vegetables | ||
</li> | ||
<li class="mdc-list-item" role="option" id="fruit" tabindex="0"> | ||
Fruit | ||
</li> | ||
<li class="mdc-list-item" role="option" id="dairy" tabindex="0"> | ||
Milk, Yogurt, and Cheese | ||
</li> | ||
<li class="mdc-list-item" role="option" id="meat" tabindex="0"> | ||
Meat, Poultry, Fish, Dry Beans, Eggs, and Nuts | ||
</li> | ||
<li class="mdc-list-item" role="option" id="fats" tabindex="0"> | ||
Fats, Oils, and Sweets | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</section> | ||
<p>Currently selected: <span id="currently-selected">(none)</span></p> | ||
<p>Currently selected: <span id="box-currently-selected">(none)</span></p> | ||
<div> | ||
<input type="checkbox" id="dark-theme"> | ||
<label for="dark-theme">Dark Theme</label> | ||
|
@@ -140,17 +134,21 @@ <h2 class="mdc-typography--title">Fully-Featured Component</h2> | |
<label for="disabled">Disabled</label> | ||
</div> | ||
</section> | ||
|
||
<section class="example"> | ||
<h2 class="mdc-typography--title">CSS Only</h2> | ||
<select class="mdc-select"> | ||
<option value="" selected>Pick a food group</option> | ||
<option value="grains">Bread, Cereal, Rice, and Pasta</option> | ||
<option value="vegetables" disabled>Vegetables</option> | ||
<option value="fruit">Fruit</option> | ||
<option value="dairy">Milk, Yogurt, and Cheese</option> | ||
<option value="meat">Meat, Poultry, Fish, Dry Beans, Eggs, and Nuts</option> | ||
<option value="fats">Fats, Oils, and Sweets</option> | ||
</select> | ||
<div class="mdc-select"> | ||
<select class="mdc-select__surface"> | ||
<option value="" selected>Pick a food group</option> | ||
<option value="grains">Bread, Cereal, Rice, and Pasta</option> | ||
<option value="vegetables" disabled>Vegetables</option> | ||
<option value="fruit">Fruit</option> | ||
<option value="dairy">Milk, Yogurt, and Cheese</option> | ||
<option value="meat">Meat, Poultry, Fish, Dry Beans, Eggs, and Nuts</option> | ||
<option value="fats">Fats, Oils, and Sweets</option> | ||
</select> | ||
<div class="mdc-select__bottom-line"></div> | ||
</div> | ||
</section> | ||
|
||
<section class="example"> | ||
|
@@ -176,40 +174,45 @@ <h2>Select Multiple - CSS Only</h2> | |
</main> | ||
<script src="/assets/material-components-web.js"></script> | ||
<script> | ||
(function() { | ||
setTimeout(function() { | ||
var MDCSelect = mdc.select.MDCSelect; | ||
var root = document.getElementById('js-select'); | ||
var currentlySelected = document.getElementById('currently-selected'); | ||
var select = MDCSelect.attachTo(root); | ||
var heroSelect = document.getElementById('hero-js-select'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in demo pages, which don't get transpiled and still need to work in all browsers we support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IE 11 (mostly) supports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if everything fully supported es2015 syntax overnight, I don't think it would be a very good use of time to re-implement the demos just for the new syntactic sugars available to us. As delicious as they may be. :) |
||
var heroSelectComponent = new mdc.select.MDCSelect(heroSelect); | ||
}, 300); | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOC, why do you have two separate script tags and IIFEs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make it easier to copy and paste for people who want to do that. |
||
<script> | ||
setTimeout(function() { | ||
var MDCSelect = mdc.select.MDCSelect; | ||
var root = document.getElementById('js-select-box'); | ||
var boxCurrentlySelected = document.getElementById('box-currently-selected'); | ||
var select = new MDCSelect(root); | ||
|
||
root.addEventListener('MDCSelect:change', function() { | ||
var item = select.selectedOptions[0]; | ||
var index = select.selectedIndex; | ||
currentlySelected.textContent = '"' + item.textContent + '" at index ' + index + | ||
' with value "' + select.value + '"'; | ||
boxCurrentlySelected.textContent = '"' + item.textContent + '" at index ' + index + | ||
' with value "' + select.value + '"'; | ||
}); | ||
|
||
var demoWrapper = document.getElementById('demo-wrapper'); | ||
var boxDemoWrapper = document.getElementById('box-demo-wrapper'); | ||
var darkThemeCb = document.getElementById('dark-theme'); | ||
var rtlCb = document.getElementById('rtl'); | ||
var disabledCb = document.getElementById('disabled'); | ||
|
||
darkThemeCb.addEventListener('change', function() { | ||
demoWrapper.classList[darkThemeCb.checked ? 'add' : 'remove']('mdc-theme--dark'); | ||
boxDemoWrapper.classList[darkThemeCb.checked ? 'add' : 'remove']('mdc-theme--dark'); | ||
}); | ||
rtlCb.addEventListener('change', function() { | ||
if (rtlCb.checked) { | ||
demoWrapper.setAttribute('dir', 'rtl'); | ||
boxDemoWrapper.setAttribute('dir', 'rtl'); | ||
} else { | ||
demoWrapper.removeAttribute('dir'); | ||
boxDemoWrapper.removeAttribute('dir'); | ||
} | ||
}); | ||
disabledCb.addEventListener('change', function() { | ||
select.disabled = disabledCb.checked; | ||
}); | ||
|
||
var heroSelect = document.getElementById('hero-js-select'); | ||
mdc.select.MDCSelect.attachTo(heroSelect); | ||
})(); | ||
}, 300); | ||
</script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were these (and not Vegetables) removed? More specifically, removing these and leaving a disabled option (with the intent of being a group header) as the last item seems like bad/confusing UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention is not about making a group header. It is about a disabled option. The others were removed for the sake of brevity.