Socket
Socket
Sign inDemoInstall

@material/textfield

Package Overview
Dependencies
8
Maintainers
11
Versions
1702
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.31.0 to 0.32.0

44

adapter.js

@@ -22,3 +22,3 @@ /**

import MDCTextFieldIconFoundation from './icon/foundation';
import MDCTextFieldLabelFoundation from './label/foundation';
import MDCFloatingLabelFoundation from '@material/floating-label/foundation';
import MDCTextFieldOutlineFoundation from './outline/foundation';

@@ -46,3 +46,3 @@

* icon: (!MDCTextFieldIconFoundation|undefined),
* label: (!MDCTextFieldLabelFoundation|undefined),
* label: (!MDCFloatingLabelFoundation|undefined),
* outline: (!MDCTextFieldOutlineFoundation|undefined)

@@ -112,2 +112,15 @@ * }}

/**
* Registers a validation attribute change listener on the input element.
* @param {function(!Array): undefined} handler
* @return {!MutationObserver}
*/
registerValidationAttributeChangeHandler(handler) {}
/**
* Disconnects a validation attribute observer on the input element.
* @param {!MutationObserver} observer
*/
deregisterValidationAttributeChangeHandler(observer) {}
/**
* Returns an object representing the native text input element, with a

@@ -152,4 +165,31 @@ * similar API shape. The object returned should include the value, disabled

setLineRippleTransformOrigin(normalizedX) {}
/**
* Only implement if label exists.
* Shakes label if shouldShake is true.
* @param {boolean} shouldShake
*/
shakeLabel(shouldShake) {}
/**
* Only implement if label exists.
* Floats the label above the input element if shouldFloat is true.
* @param {boolean} shouldFloat
*/
floatLabel(shouldFloat) {}
/**
* Returns true if label element exists, false if it doesn't.
* @return {boolean}
*/
hasLabel() {}
/**
* Only implement if label exists.
* Returns width of label in pixels.
* @return {number}
*/
getLabelWidth() {}
}
export {MDCTextFieldAdapter, NativeInputType, FoundationMapType};

2

constants.js

@@ -22,3 +22,3 @@ /**

INPUT_SELECTOR: '.mdc-text-field__input',
LABEL_SELECTOR: '.mdc-text-field__label',
LABEL_SELECTOR: '.mdc-floating-label',
ICON_SELECTOR: '.mdc-text-field__icon',

@@ -25,0 +25,0 @@ OUTLINE_SELECTOR: '.mdc-text-field__outline',

@@ -24,3 +24,3 @@ /**

import MDCTextFieldIconFoundation from './icon/foundation';
import MDCTextFieldLabelFoundation from './label/foundation';
import MDCFloatingLabelFoundation from '@material/floating-label/foundation';
import MDCTextFieldOutlineFoundation from './outline/foundation';

@@ -31,2 +31,8 @@ /* eslint-enable no-unused-vars */

// whitelist based off of https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation
// under section: `Validation-related attributes`
const VALIDATION_ATTR_WHITELIST = [
'pattern', 'min', 'max', 'required', 'step', 'minlength', 'maxlength',
];
/**

@@ -52,2 +58,12 @@ * @extends {MDCFoundation<!MDCTextFieldAdapter>}

/** @return {boolean} */
get shouldShake() {
return !this.isValid() && !this.isFocused_;
}
/** @return {boolean} */
get shouldFloat() {
return !this.isBadInput_() && (!!this.getValue() || this.isFocused_);
}
/**

@@ -67,2 +83,4 @@ * {@see MDCTextFieldAdapter} for typing information on parameters and return

deregisterInputInteractionHandler: () => {},
registerValidationAttributeChangeHandler: () => {},
deregisterValidationAttributeChangeHandler: () => {},
getNativeInput: () => {},

@@ -74,2 +92,6 @@ isFocused: () => {},

setLineRippleTransformOrigin: () => {},
shakeLabel: () => {},
floatLabel: () => {},
hasLabel: () => {},
getLabelWidth: () => {},
});

@@ -89,4 +111,2 @@ }

this.icon_ = foundationMap.icon;
/** @type {!MDCTextFieldLabelFoundation|undefined} */
this.label_ = foundationMap.label;
/** @type {!MDCTextFieldOutlineFoundation|undefined} */

@@ -113,2 +133,6 @@ this.outline_ = foundationMap.outline;

this.textFieldInteractionHandler_ = () => this.handleTextFieldInteraction();
/** @private {function(!Array): undefined} */
this.validationAttributeChangeHandler_ = (mutations) => this.handleValidationAttributeMutation_(mutations);
/** @private {!MutationObserver} */
this.validationObserver_;
}

@@ -119,5 +143,4 @@

// Ensure label does not collide with any pre-filled value.
if (this.label_ && this.getValue()) {
this.label_.styleFloat(
this.getValue(), this.isFocused_, this.isBadInput_());
if (this.adapter_.hasLabel() && this.getValue()) {
this.adapter_.floatLabel(this.shouldFloat);
}

@@ -138,2 +161,4 @@

});
this.validationObserver_ = this.adapter_.registerValidationAttributeChangeHandler(
this.validationAttributeChangeHandler_);
}

@@ -152,2 +177,3 @@

});
this.adapter_.deregisterValidationAttributeChangeHandler(this.validationObserver_);
}

@@ -166,6 +192,20 @@

/**
* Handles validation attribute changes
* @param {Array<MutationRecord>} mutationsList
* @private
*/
handleValidationAttributeMutation_(mutationsList) {
mutationsList.some((mutation) => {
if (VALIDATION_ATTR_WHITELIST.indexOf(mutation.attributeName) > -1) {
this.styleValidity_(true);
return true;
}
});
}
/**
* Updates the focus outline for outlined text fields.
*/
updateOutline() {
if (!this.outline_ || !this.label_) {
if (!this.outline_ || !this.adapter_.hasLabel()) {
return;

@@ -176,3 +216,3 @@ }

const labelScale = isDense ? numbers.DENSE_LABEL_SCALE : numbers.LABEL_SCALE;
const labelWidth = this.label_.getWidth() * labelScale;
const labelWidth = this.adapter_.getLabelWidth() * labelScale;
const isRtl = this.adapter_.isRtl();

@@ -192,6 +232,5 @@ this.outline_.updateSvgPath(labelWidth, isRtl);

}
if (this.label_) {
this.label_.styleShake(this.isValid(), this.isFocused_);
this.label_.styleFloat(
this.getValue(), this.isFocused_, this.isBadInput_());
if (this.adapter_.hasLabel()) {
this.adapter_.shakeLabel(this.shouldShake);
this.adapter_.floatLabel(this.shouldFloat);
}

@@ -236,6 +275,5 @@ if (this.helperText_) {

this.styleFocused_(this.isFocused_);
if (this.label_) {
this.label_.styleShake(this.isValid(), this.isFocused_);
this.label_.styleFloat(
this.getValue(), this.isFocused_, this.isBadInput_());
if (this.adapter_.hasLabel()) {
this.adapter_.shakeLabel(this.shouldShake);
this.adapter_.floatLabel(this.shouldFloat);
}

@@ -261,6 +299,5 @@ if (shouldRemoveLabelFloat) {

this.styleValidity_(isValid);
if (this.label_) {
this.label_.styleShake(isValid, this.isFocused_);
this.label_.styleFloat(
this.getValue(), this.isFocused_, this.isBadInput_());
if (this.adapter_.hasLabel()) {
this.adapter_.shakeLabel(this.shouldShake);
this.adapter_.floatLabel(this.shouldFloat);
}

@@ -287,4 +324,4 @@ }

this.styleValidity_(isValid);
if (this.label_) {
this.label_.styleShake(isValid, this.isFocused_);
if (this.adapter_.hasLabel()) {
this.adapter_.shakeLabel(this.shouldShake);
}

@@ -309,19 +346,2 @@ }

/**
* @return {boolean} True if the Text Field is required.
*/
isRequired() {
return this.getNativeInput_().required;
}
/**
* @param {boolean} isRequired Sets the text-field required or not.
*/
setRequired(isRequired) {
this.getNativeInput_().required = isRequired;
// Addition of the asterisk is automatic based on CSS, but validity checking
// needs to be manually run.
this.styleValidity_(this.isValid());
}
/**
* @param {string} content Sets the content of the helper text.

@@ -328,0 +348,0 @@ */

@@ -35,3 +35,3 @@ <!--docs:

<input type="text" id="username" class="mdc-text-field__input">
<label for="username" class="mdc-text-field__label">Username</label>
<label for="username" class="mdc-floating-label">Username</label>
<div class="mdc-line-ripple"></div>

@@ -55,3 +55,3 @@ </div>

<input type="text" id="username" class="mdc-text-field__input" aria-controls="username-helper-text">
<label for="username" class="mdc-text-field__label">Username</label>
<label for="username" class="mdc-floating-label">Username</label>
<div class="mdc-line-ripple"></div>

@@ -78,2 +78,10 @@ </div>

### Sass Mixins
Mixin | Description
--- | ---
`mdc-text-field-helper-text-color($color)` | Customizes the color of the helper text following a text-field.
`mdc-text-field-helper-text-validation-color($color)` | Customizes the color of the helper text when it's used as a validation message.
### `MDCTextFieldHelperText`

@@ -80,0 +88,0 @@

@@ -41,3 +41,3 @@ <!--docs:

<input type="text" id="my-input" class="mdc-text-field__input">
<label for="my-input" class="mdc-text-field__label">Your Name</label>
<label for="my-input" class="mdc-floating-label">Your Name</label>
<div class="mdc-text-field__bottom-line"></div>

@@ -52,3 +52,3 @@ </div>

<input type="text" id="my-input" class="mdc-text-field__input">
<label for="my-input" class="mdc-text-field__label">Your Name</label>
<label for="my-input" class="mdc-floating-label">Your Name</label>
<div class="mdc-text-field__outline">

@@ -69,3 +69,3 @@ <svg>

<input type="text" id="my-input" class="mdc-text-field__input">
<label for="my-input" class="mdc-text-field__label">Your Name</label>
<label for="my-input" class="mdc-floating-label">Your Name</label>
<i class="material-icons mdc-text-field__icon" tabindex="0">event</i>

@@ -80,3 +80,3 @@ <div class="mdc-text-field__bottom-line"></div>

<input type="text" id="my-input" class="mdc-text-field__input">
<label for="my-input" class="mdc-text-field__label">Your Name</label>
<label for="my-input" class="mdc-floating-label">Your Name</label>
<i class="material-icons mdc-text-field__icon" tabindex="0">event</i>

@@ -96,2 +96,8 @@ <div class="mdc-text-field__outline">

### Sass Mixins
Mixin | Description
--- | ---
`mdc-text-field-icon-color($color)` | Customizes the color for the leading/trailing icons.
### `MDCTextFieldIcon`

@@ -117,2 +123,2 @@

`setDisabled(disabled: boolean) => void` | Updates the icon's disabled state
`handleInteraction(evt: Event) => void` | Handles a text field interaction event
`handleInteraction(evt: Event) => void` | Handles a text field interaction event

@@ -32,3 +32,3 @@ /**

import {MDCTextFieldIcon, MDCTextFieldIconFoundation} from './icon/index';
import {MDCTextFieldLabel, MDCTextFieldLabelFoundation} from './label/index';
import {MDCFloatingLabel, MDCFloatingLabelFoundation} from '@material/floating-label/index';
import {MDCTextFieldOutline, MDCTextFieldOutlineFoundation} from './outline/index';

@@ -57,3 +57,3 @@ /* eslint-enable no-unused-vars */

this.icon_;
/** @private {?MDCTextFieldLabel} */
/** @private {?MDCFloatingLabel} */
this.label_;

@@ -81,4 +81,4 @@ /** @private {?MDCTextFieldOutline} */

* creates a new MDCTextFieldIcon.
* @param {(function(!Element): !MDCTextFieldLabel)=} labelFactory A function which
* creates a new MDCTextFieldLabel.
* @param {(function(!Element): !MDCFloatingLabel)=} labelFactory A function which
* creates a new MDCFloatingLabel.
* @param {(function(!Element): !MDCTextFieldOutline)=} outlineFactory A function which

@@ -92,3 +92,3 @@ * creates a new MDCTextFieldOutline.

iconFactory = (el) => new MDCTextFieldIcon(el),
labelFactory = (el) => new MDCTextFieldLabel(el),
labelFactory = (el) => new MDCFloatingLabel(el),
outlineFactory = (el) => new MDCTextFieldOutline(el)) {

@@ -213,3 +213,3 @@ this.input_ = this.root_.querySelector(strings.INPUT_SELECTOR);

get required() {
return this.foundation_.isRequired();
return this.input_.required;
}

@@ -221,6 +221,95 @@

set required(required) {
this.foundation_.setRequired(required);
this.input_.required = required;
}
/**
* @return {string} The input element's validation pattern.
*/
get pattern() {
return this.input_.pattern;
}
/**
* @param {string} pattern Sets the input element's validation pattern.
*/
set pattern(pattern) {
this.input_.pattern = pattern;
}
/**
* @return {number} The input element's minLength.
*/
get minLength() {
return this.input_.minLength;
}
/**
* @param {number} minLength Sets the input element's minLength.
*/
set minLength(minLength) {
this.input_.minLength = minLength;
}
/**
* @return {number} The input element's maxLength.
*/
get maxLength() {
return this.input_.maxLength;
}
/**
* @param {number} maxLength Sets the input element's maxLength.
*/
set maxLength(maxLength) {
// Chrome throws exception if maxLength is set < 0
if (maxLength < 0) {
this.input_.removeAttribute('maxLength');
} else {
this.input_.maxLength = maxLength;
}
}
/**
* @return {string} The input element's min.
*/
get min() {
return this.input_.min;
}
/**
* @param {string} min Sets the input element's min.
*/
set min(min) {
this.input_.min = min;
}
/**
* @return {string} The input element's max.
*/
get max() {
return this.input_.max;
}
/**
* @param {string} max Sets the input element's max.
*/
set max(max) {
this.input_.max = max;
}
/**
* @return {string} The input element's step.
*/
get step() {
return this.input_.step;
}
/**
* @param {string} step Sets the input element's step.
*/
set step(step) {
this.input_.step = step;
}
/**
* Sets the helper text element content.

@@ -257,2 +346,10 @@ * @param {string} content

deregisterTextFieldInteractionHandler: (evtType, handler) => this.root_.removeEventListener(evtType, handler),
registerValidationAttributeChangeHandler: (handler) => {
const observer = new MutationObserver(handler);
const targetNode = this.root_.querySelector(strings.INPUT_SELECTOR);
const config = {attributes: true};
observer.observe(targetNode, config);
return observer;
},
deregisterValidationAttributeChangeHandler: (observer) => observer.disconnect(),
isFocused: () => {

@@ -277,2 +374,14 @@ return document.activeElement === this.root_.querySelector(strings.INPUT_SELECTOR);

},
shakeLabel: (shouldShake) => {
this.label_.shake(shouldShake);
},
floatLabel: (shouldFloat) => {
this.label_.float(shouldFloat);
},
hasLabel: () => {
return !!this.label_;
},
getLabelWidth: () => {
return this.label_.getWidth();
},
},

@@ -306,3 +415,2 @@ this.getInputAdapterMethods_())),

icon: this.icon_ ? this.icon_.foundation : undefined,
label: this.label_ ? this.label_.foundation : undefined,
outline: this.outline_ ? this.outline_.foundation : undefined,

@@ -316,3 +424,2 @@ };

MDCTextFieldIcon, MDCTextFieldIconFoundation,
MDCTextFieldLabel, MDCTextFieldLabelFoundation,
MDCTextFieldOutline, MDCTextFieldOutlineFoundation};

@@ -40,3 +40,3 @@ <!--docs:

<input class="mdc-text-field__input" id="my-text-field-id" type="text">
<label class="mdc-text-field__label" for="my-text-field-id">Label</label>
<label class="mdc-floating-label" for="my-text-field-id">Label</label>
<div class="mdc-text-field__outline">

@@ -59,2 +59,10 @@ <svg>

### Sass Mixins
Mixin | Description
--- | ---
`mdc-text-field-outline-color($color)` | Customizes the color of the border of the outlined text-field.
`mdc-text-field-hover-outline-color($color)` | Customizes the hover color of the border of the outlined text-field.
`mdc-text-field-focused-outline-color($color)` | Customizes the outlined border color when the text-field is focused.
#### `MDCTextFieldOutline`

@@ -61,0 +69,0 @@

{
"name": "@material/textfield",
"description": "The Material Components for the web text field component",
"version": "0.31.0",
"version": "0.32.0",
"license": "Apache-2.0",

@@ -20,4 +20,5 @@ "keywords": [

"@material/base": "^0.29.0",
"@material/line-ripple": "^0.30.0",
"@material/ripple": "^0.31.0",
"@material/floating-label": "^0.32.0",
"@material/line-ripple": "^0.32.0",
"@material/ripple": "^0.32.0",
"@material/rtl": "^0.30.0",

@@ -24,0 +25,0 @@ "@material/theme": "^0.30.0",

@@ -44,3 +44,3 @@ <!--docs:

<input type="text" id="my-text-field" class="mdc-text-field__input">
<label class="mdc-text-field__label" for="my-text-field">Hint text</label>
<label class="mdc-floating-label" for="my-text-field">Hint text</label>
<div class="mdc-line-ripple"></div>

@@ -58,3 +58,3 @@ </div>

<input type="password" id="pw" class="mdc-text-field__input" required minlength=8>
<label for="pw" class="mdc-text-field__label">Password</label>
<label for="pw" class="mdc-floating-label">Password</label>
<div class="mdc-line-ripple"></div>

@@ -69,3 +69,3 @@ </div>

When dealing with JS-driven text fields that already have values, you'll want to ensure that you
render `mdc-text-field__label` with the `mdc-text-field__label--float-above` modifier class, and `mdc-text-field` with the `mdc-text-field--upgraded` modifier class. This will
render `mdc-floating-label` with the `mdc-floating-label--float-above` modifier class, and `mdc-text-field` with the `mdc-text-field--upgraded` modifier class. This will
ensure that the label moves out of the way of the text field's value and prevents a Flash Of

@@ -77,3 +77,3 @@ Un-styled Content (**FOUC**).

<input type="text" id="pre-filled" class="mdc-text-field__input" value="Pre-filled value">
<label class="mdc-text-field__label mdc-text-field__label--float-above" for="pre-filled">
<label class="mdc-floating-label mdc-floating-label--float-above" for="pre-filled">
Label in correct place

@@ -100,3 +100,3 @@ </label>

> _NOTE_: Do not use `mdc-text-field__label` within `mdc-text-field--fullwidth`. Labels should not be
> _NOTE_: Do not use `mdc-floating-label` within `mdc-text-field--fullwidth`. Labels should not be
included as part of the DOM structure of a full width text field.

@@ -109,3 +109,3 @@

<textarea id="textarea" class="mdc-text-field__input" rows="8" cols="40"></textarea>
<label for="textarea" class="mdc-text-field__label">Textarea Label</label>
<label for="textarea" class="mdc-floating-label">Textarea Label</label>
</div>

@@ -121,3 +121,3 @@ ```

<input type="text" id="disabled-text-field" class="mdc-text-field__input" disabled>
<label class="mdc-text-field__label" for="disabled-text-field">Disabled text field</label>
<label class="mdc-floating-label" for="disabled-text-field">Disabled text field</label>
<div class="mdc-line-ripple"></div>

@@ -132,3 +132,3 @@ </div>

<input type="text" id="tf-outlined" class="mdc-text-field__input">
<label for="tf-outlined" class="mdc-text-field__label">Your Name</label>
<label for="tf-outlined" class="mdc-floating-label">Your Name</label>
<div class="mdc-text-field__outline">

@@ -185,19 +185,14 @@ <svg>

--- | ---
`mdc-text-field-box-corner-radius($radius)` | Customizes the border radius for a box text field
`mdc-text-field-textarea-corner-radius($radius)` | Customizes the border radius for a `<textarea>` text field
`mdc-text-field-bottom-line-color($color)` | Customizes the text-field bottom line color except the outline and textarea variants.
`mdc-text-field-box-corner-radius($radius)` | Customizes the border radius for the text-field box variant.
`mdc-text-field-box-fill-color($color)` | Customizes the background color of the text-field box.
`mdc-text-field-fullwidth-bottom-line-color($color)` | Customizes the fullwidth text-field variant bottom line color.
`mdc-text-field-hover-bottom-line-color($color)` | Customizes the hover text-field bottom line color except the outline and textarea variants.
`mdc-text-field-ink-color($color)` | Customizes the text entered into the text-field.
`mdc-text-field-label-color($color)` | Customizes the label color of the text-field.
`mdc-text-field-label-color($color)` | Customizes the text color of the label.
`mdc-text-field-line-ripple-color($color)` | Customizes the color of the default line ripple of the text-field.
`mdc-text-field-hover-line-ripple-color($color)` | Customizes the hover color of the line ripple of the text-field.
`mdc-text-field-focused-line-ripple-color($color)` | Customizes the line-ripple ripple color when the text-field is focused.
`mdc-text-field-outline-color($color)` | Customizes the color of the border of the outlined text-field.
`mdc-text-field-hover-outline-color($color)` | Customizes the hover color of the border of the outlined text-field.
`mdc-text-field-focused-outline-color($color)` | Customizes the outlined border color when the text-field is focused.
`mdc-text-field-box-fill-color($color)` | Customizes the background color of the text-field box.
`mdc-text-field-outlined-corner-radius($radius)` | Sets the border radius of of the text-field outline variant.
`mdc-text-field-textarea-corner-radius($radius)` | Customizes the border radius for a `<textarea>` variant.
`mdc-text-field-textarea-fill-color($color)` | Customizes the color of the background of the textarea.
`mdc-text-field-textarea-stroke-color($color)` | Customizes the color of the border of the textarea.
`mdc-text-field-textarea-fill-color($color)` | Customizes the color of the background of the textarea.
`mdc-text-field-fullwidth-line-ripple-color($color)` | Customizes the line ripple under a fullwidth text field. Doesn't apply to a textarea.
`mdc-text-field-icon-color($color)` | Customizes the color for the leading/trailing icons.
`mdc-text-field-helper-text-color($color)` | Customizes the color of the helper text following a text-field.
`mdc-text-field-helper-text-validation-color($color)` | Customizes the color of the helper text when it's used as a validation message.

@@ -266,2 +261,2 @@ ### `MDCTextField`

`MDCTextFieldFoundation` supports multiple optional sub-elements: line ripple, helper text, icon, label, and outline. The foundations of these sub-elements must be passed in as constructor arguments to `MDCTextFieldFoundation`.
`MDCTextFieldFoundation` supports multiple optional sub-elements: line ripple, helper text, icon, and outline. The foundations of these sub-elements must be passed in as constructor arguments to `MDCTextFieldFoundation`.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc