![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@material/form-field
Advanced tools
Material Components for the web wrapper for laying out form fields and labels next to one another
MDC Form Field aligns an MDC Web form field (for example, a checkbox) with its label and makes it RTL-aware. It also activates a ripple effect upon interacting with the label.
npm install @material/form-field
Use the mdc-form-field
element to wrap any combination of adjacent input and label elements of MDC Web form controls, such as MDC Checkbox or MDC Radio. Here's an example with MDC Checkbox:
<div class="mdc-form-field">
<div class="mdc-checkbox">
<input type="checkbox" id="my-checkbox" class="mdc-checkbox__native-control"/>
<div class="mdc-checkbox__background">
...
</div>
</div>
<label for="my-checkbox">This is my checkbox</label>
</div>
NOTE: MDC Form Field is not intended for cases where a label and input are already handled together in a component's styles and logic. For example, MDC Text Field already manages a label and input together under its own root element.
If you are using MDC Form Field with an MDC Web component that has a ripple effect, you can instantiate MDCFormField
and set its input
property to activate the ripple effect upon interacting with the label. Here is an example with MDC Checkbox:
import {MDCFormField} from '@material/form-field';
import {MDCCheckbox} from '@material/checkbox';
const formField = new MDCFormField(document.querySelector('.mdc-form-field'));
const checkbox = new MDCCheckbox(document.querySelector('.mdc-checkbox'));
formField.input = checkbox;
See Importing the JS component for more information on how to import JavaScript.
By default, the input will be positioned before the label. You can position the input after the label by adding the mdc-form-field--align-end
class:
<div class="mdc-form-field mdc-form-field--align-end">
<div class="mdc-checkbox">
<input type="checkbox" id="my-checkbox" class="mdc-checkbox__native-control"/>
<div class="mdc-checkbox__background">
...
</div>
</div>
<label for="my-checkbox">This is my checkbox</label>
</div>
MDCFormField
Properties and MethodsProperty | Value Type | Description |
---|---|---|
input | String | Gets and sets the form field input. |
In order for the label ripple integration to work correctly, the input
property needs to be set to a valid instance of an MDC Web input element which exposes a ripple
getter. No action is taken if the input
property is not set or the input instance doesn't expose a ripple
getter.
If you are using a JavaScript framework, such as React or Angular, you can create a Form Field for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.
MDCFormFieldAdapter
Method Signature | Description |
---|---|
registerInteractionHandler(type: string, handler: EventListener) => void | Adds an event listener handler for event type type to the label. |
deregisterInteractionHandler(type: string, handler: EventListener) => void | Removes an event listener handler for event type type to the label. |
activateInputRipple() => void | Activates the ripple on the input element. Should call activate on the input element's ripple property. |
deactivateInputRipple() => void | Deactivates the ripple on the input element. Should call deactivate on the input element's ripple property. |
6.0.0 (2020-04-22)
[@use](https://github.com/use)
(098ae32)indeterminate
checkbox (b273afa)select: HTML Markup significantly changed, see README; REMOVED adapter methods isSelectedTextFocused
, getSelectedTextAttr
, setSelectedTextAttr
; ADDED adapter methods isSelectAnchorFocused
, getSelectAnchorAttr
, setSelectAnchorAttr
; removed variables outlined-dense-label-position-y
, icon-padding
; added variables minimum-height-for-filled-label
, filled-baseline-top
, selected-text-height
, anchor-padding-left
, anchor-padding-left-with-leading-icon
, anchor-padding-right
.
text-field: Redundant mixins mdc-text-field-textarea-fill-color
, mdc-text-field-textarea-stroke-color
, mdc-text-field-fullwidth-bottom-line-color
removed. Instead, use mdc-text-field-fill-color
, mdc-text-field-outline-color
, and mdc-text-field-bottom-line-color
respectively to achieve the same effect.
textfield: mdc-text-field--dense and associated mixins/variables have been removed. Use the density() mixin instead.
textfield: removed the following variables: $input-padding
, $input-padding-top
, $input-padding-bottom
, $outlined-input-padding-top
, $outlined-input-padding-bottom
, $input-border-bottom
linear-progress: DOM for linear progress buffer changed. MDCLinearProgressAdapter method getBuffer
, getPrimaryBar
, setStyle
removed. MDCLinearProgressAdapter method setBufferBarStyle
, setPrimaryBarStyle
added.
linear-progress: DOM for linear progress buffer changed. MDCLinearProgressAdapter method getBuffer
, getPrimaryBar
, setStyle
removed. MDCLinearProgressAdapter method setBufferBarStyle
, setPrimaryBarStyle
added.
typography: typography.baseline-top()
and typography.baseline-bottom()
are now private. Use typography.baseline()
for containers and typography.text-baseline()
for text with $top and $bottom params.
chips: The touch target and text now appear inside the primary action element. Please see the readme for markup changes.
textfield: filled text fields must include a <div class="mdc-text-field__ripple"></div>
textfield: Filled textfields will no longer show a floating label at certain densities. This can be overridden by setting $mdc-text-field-minimum-height-for-filled-label: 40px
chips: Both MDCChipAdapter
and MDCChipSetAdapter
have new methods. MDCChipSetFoundation
event handlers now accept the corresponding chip event detail interface as the sole argument. The root
property has been removed from the MDCChipRemovalEventDetail
interface.
line-ripple: mdc-line-ripple-color()
mixin has been renamed to mdc-line-ripple-active-color()
textfield: Default textfields must now specify mdc-text-field--filled. Disabled outlined textfields no longer have a shaded background. Height mixin no longer specifies a baseline override, use typography's baseline-top mixin.
Four variables and a mixin in mdc-textfield were renamed to use a mdc-text-field- prefix when depended on via @import (formerly mdc-required-text-field-label-asterisk_, now required-label-asterisk_).
textfield: icons must use .mdc-text-field__icon--leading
or .mdc-text-field__icon--trailing
classes. mdc-text-field-icon-color()
mixin has been split into mdc-text-field-leading-icon-color()
and mdc-text-field-trailing-icon-color()
.
switch: Added setNativeControlAttr method in mdc-switch adapter.
checkbox: remove event listener for 'change' and add event listener for 'click'.
$mdc-button-disabled-container-fill-color
renamed to $mdc-button-disabled-container-color
.$edgeOptOut
option from mdc-theme-prop()
Sass mixin.FAQs
Material Components for the web wrapper for laying out form fields and labels next to one another
The npm package @material/form-field receives a total of 469,238 weekly downloads. As such, @material/form-field popularity was classified as popular.
We found that @material/form-field demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.