Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit f44721c

Browse files
authoredJan 31, 2018
feat(select): Remove css version (#2116)
BREAKING CHANGE: Removes the CSS version of the mdc-select element.
1 parent 220168a commit f44721c

File tree

4 files changed

+4
-170
lines changed

4 files changed

+4
-170
lines changed
 

‎demos/select.html

-38
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,6 @@ <h2 class="mdc-typography--title">Fully-Featured Component</h2>
134134
<label for="disabled">Disabled</label>
135135
</div>
136136
</section>
137-
138-
<section class="example">
139-
<h2 class="mdc-typography--title">CSS Only</h2>
140-
<section class="box-demo-wrapper">
141-
<div id="demo-css-only-select" class="mdc-select">
142-
<select class="mdc-select__surface">
143-
<option value="" selected>Pick a food group</option>
144-
<option value="grains">Bread, Cereal, Rice, and Pasta</option>
145-
<option value="vegetables" disabled>Vegetables</option>
146-
<option value="fruit">Fruit</option>
147-
<option value="dairy">Milk, Yogurt, and Cheese</option>
148-
<option value="meat">Meat, Poultry, Fish, Dry Beans, Eggs, and Nuts</option>
149-
<option value="fats">Fats, Oils, and Sweets</option>
150-
</select>
151-
<div class="mdc-select__bottom-line"></div>
152-
</div>
153-
</section>
154-
<div>
155-
<input type="checkbox" id="css-alternate-colors">
156-
<label for="css-alternate-colors">Alternate Colors</label>
157-
</div>
158-
<div>
159-
<input type="checkbox" id="css-disabled">
160-
<label for="css-disabled">Disabled</label>
161-
</div>
162-
</section>
163137
</main>
164138

165139
<script src="/assets/material-components-web.js" async></script>
@@ -183,11 +157,6 @@ <h2 class="mdc-typography--title">CSS Only</h2>
183157
var alternateColorsCb = document.getElementById('alternate-colors');
184158
var disabledCb = document.getElementById('disabled');
185159

186-
// CSS
187-
var selectCss = document.getElementById('demo-css-only-select');
188-
var cssAlternateColors = document.getElementById('css-alternate-colors');
189-
var cssDisabled = document.getElementById('css-disabled');
190-
191160
rtlCb.addEventListener('change', function() {
192161
if (rtlCb.checked) {
193162
boxDemoWrapper.setAttribute('dir', 'rtl');
@@ -201,13 +170,6 @@ <h2 class="mdc-typography--title">CSS Only</h2>
201170
disabledCb.addEventListener('change', function() {
202171
select.disabled = disabledCb.checked;
203172
});
204-
205-
cssAlternateColors.addEventListener('change', function() {
206-
selectCss.classList[cssAlternateColors.checked ? 'add' : 'remove']('demo-select-custom-colors');
207-
});
208-
cssDisabled.addEventListener('change', function() {
209-
cssDisabled.checked ? selectCss.setAttribute('disabled', 'disabled') : selectCss.removeAttribute('disabled');
210-
});
211173
});
212174
</script>
213175
</body>

‎packages/mdc-select/README.md

+2-121
Original file line numberDiff line numberDiff line change
@@ -200,37 +200,11 @@ To disable a list item, set `aria-disabled` to `"true"`, and set `tabindex` to `
200200
</div>
201201
```
202202

203-
### Using the Pure CSS Select
204-
205-
The `mdc-select` CSS classes also work with the browser's native `<select>` element, allowing for a
206-
seamless, un-invasive experience in browsers where a native select may be more appropriate, such as
207-
on a mobile device. It does not require any javascript, nor any CSS for `mdc-menu` or `mdc-list`.
208-
E.g.:
209-
210-
1. Wrap the `<select>` with a block element that has an `mdc-select` class
211-
2. Add the `mdc-select__surface` class to the `<select>`
212-
3. Append `<div class="mdc-select__bottom-line"></div>` immediately after the `<select>`
213-
214-
```html
215-
<div class="mdc-select">
216-
<select class="mdc-select__surface">
217-
<option value="" default selected>Pick a food group</option>
218-
<option value="grains">Bread, Cereal, Rice, and Pasta</option>
219-
<option value="vegetables" disabled>Vegetables</option>
220-
<option value="fruit">Fruit</option>
221-
<option value="dairy">Milk, Yogurt, and Cheese</option>
222-
<option value="meat">Meat, Poultry, Fish, Dry Beans, Eggs, and Nuts</option>
223-
<option value="fats">Fats, Oils, and Sweets</option>
224-
</select>
225-
<div class="mdc-select__bottom-line"></div>
226-
</div>
227-
```
228-
229203
#### CSS Classes
230204

231205
| Class | Description |
232206
| ------------------------ | ----------------------------------------------- |
233-
| `mdc-select` | A pure css `select` element |
207+
| `mdc-select` | Mandatory. |
234208
| `mdc-list-group` | A group of options. |
235209
| `mdc-list-item` | A list item. |
236210
| `mdc-list-divider` | A divider. |
@@ -244,7 +218,7 @@ these mixins within CSS selectors like `.foo-select` to apply styling.
244218

245219
Mixin | Description
246220
--- | ---
247-
`mdc-select-ink-color($color)` | Customizes the color of the selected item displayed in the select. On the css version, this also customizes the color of the label.
221+
`mdc-select-ink-color($color)` | Customizes the color of the selected item displayed in the select.
248222
`mdc-select-container-fill-color($color)` | Customizes the background color of the select.
249223
`mdc-select-label-color($color)` | Customizes the label color of the select in the unfocused state. This mixin is only used for the JS version of the select.
250224
`mdc-select-focused-label-color($color, $opacity: 0.87)` | Customizes the label color of the select when focused. Changing opacity for the label when floating is optional.
@@ -393,96 +367,3 @@ Enables/disables the select.
393367
## Theming
394368

395369
The select's bottom border is set to the current theme's primary color when focused.
396-
397-
## Tips / Tricks
398-
399-
### Switching between selects for better cross-device UX
400-
401-
Selects are a tricky beast on the web. Many times, a custom select component will work well on large
402-
devices with mouse/keyboard capability, but fail miserably on smaller-scale devices without
403-
fine-grained pointer capability, such as a phone. Because `mdc-select` works on native selects, you
404-
can easily switch between a custom select on larger devices and a native element on smaller ones.
405-
406-
First, wrap both a custom select and a native select within a wrapper element, let's call it the
407-
`select-manager`.
408-
409-
```html
410-
<div class="select-manager">
411-
<!-- Custom MDC Select, shown on desktop -->
412-
<div class="mdc-select" role="listbox">
413-
<div class="mdc-select__surface" tabindex="0">
414-
<div class="mdc-select__label">Pick One</div>
415-
<div class="mdc-select__selected-text"></div>
416-
<div class="mdc-select__bottom-line"></div>
417-
</div>
418-
<div class="mdc-menu mdc-select__menu">
419-
<ul class="mdc-list mdc-menu__items">
420-
<li id="a" class="mdc-list-item" role="option" tabindex="0">A</li>
421-
<li id="b" class="mdc-list-item" role="option" tabindex="0">B</li>
422-
<li id="c" class="mdc-list-item" role="option" tabindex="0">C</li>
423-
</ul>
424-
</div>
425-
</div>
426-
<!-- Native element, shown on mobile devices -->
427-
<div class="mdc-select">
428-
<select class="mdc-select__surface">
429-
<option value="" selected disabled>Pick one</option>
430-
<option value="a">A</option>
431-
<option value="b">B</option>
432-
<option value="c">C</option>
433-
</select>
434-
<div class="mdc-select__bottom-line"></div>
435-
<div>
436-
</div>
437-
```
438-
439-
Then, write some CSS that implements a media query checking for a small screen as well as
440-
[course pointer interaction](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer). This
441-
will ensure that the custom select will still be present on smaller devices that do have
442-
mouse/keyboard capability, such as a hybrid tablet or a small browser window on a desktop.
443-
444-
```css
445-
.select-manager > select.mdc-select {
446-
display: none;
447-
}
448-
449-
@media (max-width: 600px) and (pointer: coarse) {
450-
.select-manager > .mdc-select[role="listbox"] {
451-
display: none;
452-
}
453-
454-
.select-manager > select.mdc-select {
455-
display: block;
456-
}
457-
}
458-
```
459-
460-
Finally, we need to be able to react to events and keep each component in sync. We can do this in
461-
a few lines of JS, and check where the event came from by looking at its `type`. If it came from the
462-
custom component, the type will be `MDCSelect:change`, otherwise it will simply be `change`.
463-
464-
```js
465-
const selectManager = document.querySelector('.select-manager');
466-
const selects = {
467-
custom: MDCSelect.attachTo(selectManager.querySelector('.mdc-select[role="listbox"]')),
468-
native: MDCSelect.attachTo(selectManager.querySelector('select.mdc-select__surface'))
469-
};
470-
const changeHandler = ({type}) => {
471-
let changedSelect, selectToUpdate, value;
472-
if (type === 'MDCSelect:change') {
473-
changedSelect = selects.custom;
474-
selectToUpdate = selects.native;
475-
value = changedSelect.selectedOptions[0].id;
476-
} else {
477-
changedSelect = selects.native;
478-
selectToUpdate = selects.custom;
479-
value = changedSelect.selectedOptions[0].value;
480-
}
481-
selectToUpdate.selectedIndex = changedSelect.selectedIndex;
482-
console.info('Selected value', value);
483-
};
484-
selects.custom.listen('MDCSelect:change', changeHandler);
485-
selects.native.addEventListener('change', changeHandler);
486-
```
487-
488-
We are looking into building this functionality into `MDCSelect` in the future.

‎packages/mdc-select/_mixins.scss

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
// Private
5656

5757
@mixin mdc-select-focused-bottom-line_ {
58-
// JS-enhanced and CSS-only Selects require different selectors for focused bottom-line due to different DOM structure
59-
.mdc-select__surface:focus .mdc-select__bottom-line,
60-
.mdc-select__surface:focus ~ .mdc-select__bottom-line {
58+
.mdc-select__surface:focus .mdc-select__bottom-line {
6159
@content;
6260
}
6361
}

‎packages/mdc-select/mdc-select.scss

+1-8
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
7373
@include mdc-ripple-radius-bounded;
7474
@include mdc-states;
7575

76-
&::-ms-expand {
77-
display: none;
78-
}
79-
8076
display: flex;
8177
position: relative;
8278
flex-grow: 1;
@@ -85,8 +81,6 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
8581
border: none;
8682
border-radius: 4px 4px 0 0;
8783
outline: none;
88-
// Resets for <select> element
89-
appearance: none;
9084
overflow: hidden;
9185
}
9286

@@ -179,8 +173,7 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
179173
}
180174
}
181175

182-
.mdc-select--disabled,
183-
.mdc-select[disabled] {
176+
.mdc-select--disabled {
184177
@include mdc-select-label-color_(text-disabled-on-light);
185178
@include mdc-select-dd-arrow-svg-bg_(000000, .38);
186179

0 commit comments

Comments
 (0)