-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
select(refactor): decouple label from select #2244
Changes from 3 commits
8a31575
e364725
7092bb3
c80ef55
605c269
1fe387f
42af9cf
bc99e5e
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "@material/animation/variables"; | ||
|
||
$mdc-select-arrow-padding: 26px; | ||
$mdc-select-label-padding: 16px; | ||
$mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timing-function; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,7 @@ export default class MDCSelectFoundation extends MDCFoundation { | |
return { | ||
addClass: (/* className: string */) => {}, | ||
removeClass: (/* className: string */) => {}, | ||
addClassToLabel: (/* className: string */) => {}, | ||
removeClassFromLabel: (/* className: string */) => {}, | ||
floatLabel: (/* value: boolean */) => {}, | ||
addClassToBottomLine: (/* className: string */) => {}, | ||
removeClassFromBottomLine: (/* className: string */) => {}, | ||
setBottomLineAttr: (/* attr: string, value: string */) => {}, | ||
|
@@ -153,9 +152,9 @@ export default class MDCSelectFoundation extends MDCFoundation { | |
if (this.selectedIndex_ >= 0) { | ||
selectedTextContent = this.adapter_.getTextForOptionAtIndex(this.selectedIndex_).trim(); | ||
this.adapter_.setAttrForOptionAtIndex(this.selectedIndex_, 'aria-selected', 'true'); | ||
this.adapter_.addClassToLabel(cssClasses.LABEL_FLOAT_ABOVE); | ||
this.adapter_.floatLabel(true); | ||
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. We looked up the spec yesterday and saw that this should be moved to the open function, and line 157 should be moved to the closed function. |
||
} else { | ||
this.adapter_.removeClassFromLabel(cssClasses.LABEL_FLOAT_ABOVE); | ||
this.adapter_.floatLabel(false); | ||
} | ||
this.adapter_.setSelectedTextContent(selectedTextContent); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<!--docs: | ||
title: "Select Label" | ||
layout: detail | ||
section: components | ||
iconId: menu | ||
path: /catalog/input-controls/select-menus/ | ||
--> | ||
|
||
# Select Label | ||
|
||
<!--<div class="article__asset"> | ||
<a class="article__asset-link" | ||
href="https://material-components-web.appspot.com/select.html"> | ||
<img src="{{ site.rootpath }}/images/mdc_web_screenshots/selects.png" width="376" alt="Select screenshot"> | ||
</a> | ||
</div>--> | ||
|
||
Select labels display the type of input a field requires. Every select should have a label. Labels are aligned with the input line and always visible. They can be resting (when a select is inactive and empty) or floating. The label is a text caption or description for the select. | ||
|
||
## Design & API Documentation | ||
|
||
<ul class="icon-list"> | ||
<li class="icon-list-item icon-list-item--spec"> | ||
<a href="https://material.io/guidelines/components/text-fields.html">Material Design guidelines: Text Fields</a> | ||
</li> | ||
<li class="icon-list-item icon-list-item--spec"> | ||
<a href="https://material.io/guidelines/components/menus.html">Material Design guidelines: Menus</a> | ||
</li> | ||
<li class="icon-list-item icon-list-item--link"> | ||
<a href="https://material-components-web.appspot.com/select.html">Demo</a> | ||
</li> | ||
</ul> | ||
|
||
## Usage | ||
|
||
### HTML Structure | ||
|
||
```html | ||
<div class="mdc-select__label" for="my-select-id">Hint text</div> | ||
``` | ||
|
||
### Usage within `mdc-select` | ||
|
||
```html | ||
<div class="mdc-select" role="listbox"> | ||
<div class="mdc-select__surface" tabindex="0"> | ||
<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-menu mdc-select__menu"> | ||
<ul class="mdc-list mdc-menu__items"> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Dairy | ||
</li> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Vegetables | ||
</li> | ||
<li class="mdc-list-item" role="option" tabindex="0"> | ||
Fruit | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
``` | ||
|
||
### CSS Classes | ||
|
||
CSS Class | Description | ||
--- | --- | ||
`mdc-select__label` | Mandatory | ||
`mdc-select__label--float-above` | Indicates the label is floating above the select | ||
|
||
### `MDCSelectLabel` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
`float(value: string)` | Styles the label to float or defloat as necessary. | ||
|
||
### `MDCSelectLabelAdapter` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
`addClass(className: string) => void` | Adds a class to the label element. | ||
`removeClass(className: string) => void` | Removes a class from the label element. | ||
|
||
### `MDCSelectLabelFoundation` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
`styleFloat(value: string)` | Adds or removes the float-above selector to the label element. | ||
|
||
### Sass Mixins | ||
|
||
Mixin | Description | ||
--- | --- | ||
`mdc-select-floating-label-color($color)` | Customizes the color of the label element. |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||
// | ||||
// Copyright 2018 Google Inc. All Rights Reserved. | ||||
// | ||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||
// you may not use this file except in compliance with the License. | ||||
// You may obtain a copy of the License at | ||||
// | ||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||
// | ||||
// Unless required by applicable law or agreed to in writing, software | ||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
// See the License for the specific language governing permissions and | ||||
// limitations under the License. | ||||
// | ||||
|
||||
@import "@material/theme/mixins"; | ||||
|
||||
@mixin mdc-select-floating-label-color($color, $opacity: 1) { | ||||
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 this be private ? 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. In the current implementation in #2237 it is public. It needs to be public for other modules to change the color. Why do you think it needs to be private? 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 thought public color mixins were supposed to explicitly prevent styling the disabled state
That doesn't really make sense for the separate package though, so maybe it doesn't matter. 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 think it doesn't make sense to have that in the public mixin, but I guess the question then is, should we allow the end developer to style the color in the disabled state? Also in the current state being in the label module, we shouldn't add in parent classes like .mdc-text-field--disabled or .mdc-select--disabled 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 think we're explicitly preventing them from styling the disabled state. It doesn't make sense to include the parent class, we added proxy mixins from the parent to the line-ripple module to prevent customizing the disabled state. |
||||
.mdc-select__label { | ||||
@include mdc-theme-prop(color, rgba(mdc-theme-prop-value($color), $opacity)); | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* eslint no-unused-vars: [2, {"args": "none"}] */ | ||
|
||
/** | ||
* Adapter for MDC Select Label. | ||
* | ||
* Defines the shape of the adapter expected by the foundation. Implement this | ||
* adapter to integrate the Select label into your framework. See | ||
* https://github.com/material-components/material-components-web/blob/master/docs/authoring-components.md | ||
* for more information. | ||
* | ||
* @record | ||
*/ | ||
class MDCSelectLabelAdapter { | ||
/** | ||
* Adds a class to the label element. | ||
* @param {string} className | ||
*/ | ||
addClass(className) {} | ||
|
||
/** | ||
* Removes a class from the label element. | ||
* @param {string} className | ||
*/ | ||
removeClass(className) {} | ||
} | ||
|
||
export default MDCSelectLabelAdapter; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const cssClasses = { | ||
LABEL_FLOAT_ABOVE: 'mdc-select__label--float-above', | ||
}; |
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.
I don't think we should be adding docs for instantiating this sub component.
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.
Will remove