-
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 5 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 |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
} | ||
|
||
.example { | ||
max-width: 400px; | ||
margin: 24px; | ||
padding: 24px; | ||
} | ||
|
@@ -66,12 +67,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> | ||
|
@@ -81,7 +83,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"> | ||
|
@@ -97,37 +99,30 @@ | |
|
||
<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> | ||
|
@@ -141,19 +136,25 @@ <h2 class="mdc-typography--title">Fully-Featured Component</h2> | |
<label for="disabled">Disabled</label> | ||
</div> | ||
</section> | ||
|
||
|
||
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. Is this second blank line intentional? 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. It is not. Assume all extraneous white space is a d'oh on my part :) |
||
<section class="example"> | ||
<h2 class="mdc-typography--title">CSS Only</h2> | ||
<select class="mdc-select"> | ||
<option value="" default 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="" default selected>Pick a food group</option> | ||
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. I don't think 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. Whoa. Yep. |
||
<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> | ||
|
||
|
||
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. Is this extra blank line intentional? |
||
<section class="example"> | ||
<h2>Select Multiple - CSS Only</h2> | ||
<select multiple size="8" class="mdc-multi-select mdc-list"> | ||
|
@@ -179,37 +180,42 @@ <h2>Select Multiple - CSS Only</h2> | |
<script> | ||
(function() { | ||
var MDCSelect = mdc.select.MDCSelect; | ||
var root = document.getElementById('js-select'); | ||
var currentlySelected = document.getElementById('currently-selected'); | ||
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. :) |
||
mdc.select.MDCSelect.attachTo(heroSelect); | ||
})(); | ||
</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> | ||
(function() { | ||
var MDCSelect = mdc.select.MDCSelect; | ||
var root = document.getElementById('js-select-box'); | ||
var boxCurrentlySelected = document.getElementById('box-currently-selected'); | ||
var select = MDCSelect.attachTo(root); | ||
|
||
root.addEventListener('MDCSelect:change', function() { | ||
var item = select.selectedOptions[0]; | ||
var index = select.selectedIndex; | ||
currentlySelected.textContent = '"' + item.textContent + '" at index ' + index + | ||
boxCurrentlySelected.textContent = '"' + item.textContent + '" at index ' + index + | ||
' with value "' + select.value + '"'; | ||
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. I know we don't lint our demo code, but could we possibly reindent this line while we're here? 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.
|
||
}); | ||
|
||
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); | ||
})(); | ||
</script> | ||
</body> | ||
|
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.