Skip to content

Commit

Permalink
feat(formfield): add spaceBetween and new story tests #1041
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 305342837
  • Loading branch information
asyncLiz authored and copybara-github committed Apr 7, 2020
1 parent a0ab877 commit 8d35230
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added surface/on-surface theme properties for mwc-switch
- Added overrides for ripple focus and hover opacities
- `--mdc-ripple-focus-opacity` and `--mdc-ripple-hover-opacity` respectively
- Added `spaceBetween` to mwc-formfield

### Changed

Expand Down
2 changes: 2 additions & 0 deletions packages/formfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Name | Description
Name | Type | Description
------- | -------- | ----------------------------------
`label` | `string` | The text to display for the label.
`alignEnd` | `boolean` | Align the component at the end of the label.
`spaceBetween` | `boolean` | Add space between the component and the label as the formfield grows.

### Methods

Expand Down
10 changes: 7 additions & 3 deletions packages/formfield/src/mwc-formfield-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {classMap} from 'lit-html/directives/class-map.js';

export class FormfieldBase extends BaseElement {
@property({type: Boolean}) alignEnd = false;
@property({type: Boolean}) spaceBetween = false;

@property({type: String})
@observer(async function(this: FormfieldBase, label: string) {
Expand Down Expand Up @@ -90,10 +91,13 @@ export class FormfieldBase extends BaseElement {
}

protected render() {
const classes = {
'mdc-form-field--align-end': this.alignEnd,
'mdc-form-field--space-between': this.spaceBetween
};

return html`
<div class="mdc-form-field ${classMap({
'mdc-form-field--align-end': this.alignEnd
})}">
<div class="mdc-form-field ${classMap(classes)}">
<slot></slot>
<label class="mdc-label"
@click="${this._labelClick}">${this.label}</label>
Expand Down
8 changes: 6 additions & 2 deletions packages/formfield/src/mwc-formfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ limitations under the License.

@import '@material/form-field/mdc-form-field.scss';

:host {
display: inline-flex;
}

.mdc-form-field {
align-items: center;
width: 100%;
}

::slotted(*) {
Expand All @@ -31,4 +35,4 @@ limitations under the License.
@include mdc-rtl {
margin-left: 10px;
}
}
}

0 comments on commit 8d35230

Please sign in to comment.