npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@loipham/material-form-field

v14.0.4

Published

Material Components for the web wrapper for laying out form fields and labels next to one another

Downloads

1

Readme

Form Fields

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.

Installation

npm install @loipham/material-form-field

Demos

Basic Usage

HTML Structure

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.

JavaScript Instantiation

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 '@loipham/material-form-field';
import {MDCCheckbox} from '@loipham/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.

Variants

Label position

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>

Nowrap

If the label text is too long for a single line, it will wrap the text by default. You can force the text to stay on a single line and ellipse the overflow text by adding the mdc-form-field--nowrap class:

<div class="mdc-form-field mdc-form-field--nowrap">
  <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 some really really really long text</label>
</div>

MDCFormField Properties and Methods

Property | 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.

Usage within Web Frameworks

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. |