Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ <h2>Inputs</h2>
label="Preferred Date"
required
minlength="4"></md-text-field>
<md-text-field
color="outlined"
id="themeColor"
type="color"
label="Theme Color"
value="#6750a4"></md-text-field>
<md-button onclick="save()">Save</md-button>

<script>
Expand Down
2 changes: 2 additions & 0 deletions text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<md-text-field color="outlined"></md-text-field>

<md-text-field color="filled"></md-text-field>

<md-text-field type="color" label="Color" value="#6750a4"></md-text-field>
```
44 changes: 43 additions & 1 deletion text/text-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export class TextField extends textFieldBaseClass {
* - search
* - tel
* - url
* - color
*
* See
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
Expand Down Expand Up @@ -432,7 +433,7 @@ export class TextField extends textFieldBaseClass {
?has-start=${this.hasLeadingIcon}
label=${this.label}
max=${this.maxLength}
?populated=${!!this.value}
?populated=${!!this.value || this.type === 'color'}
?required=${this.required}
?resizable=${this.type === 'textarea'}
supporting-text=${this.supportingText}
Expand Down Expand Up @@ -751,6 +752,10 @@ __decorate([
resize: inherit;
}

:host([type='color']) .field {
cursor: pointer;
}

.icon {
color: currentColor;
display: flex;
Expand Down Expand Up @@ -817,6 +822,43 @@ __decorate([
-moz-appearance: textfield;
}

.input[type='color'] {
appearance: auto;
-webkit-appearance: auto;
box-sizing: border-box;
cursor: pointer;
height: 28px;
min-height: 28px;
width: 100%;
border: none;
background: none;
padding: 0;
margin: 0;
vertical-align: middle;
}

.input[type='color']::-webkit-color-swatch-wrapper {
padding: 0;
}

.input[type='color']::-webkit-color-swatch {
border: 1px solid var(--_outline-color, rgba(0, 0, 0, 0.2));
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
box-sizing: border-box;
}

.input[type='color']::-moz-color-swatch {
border: 1px solid var(--_outline-color, rgba(0, 0, 0, 0.2));
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
box-sizing: border-box;
}

:host([disabled]) .input[type='color'] {
cursor: default;
pointer-events: none;
opacity: var(--_disabled-input-text-opacity, 0.38);
}

:focus-within .input {
caret-color: var(--_focus-caret-color);
}
Expand Down
Loading