Socket
Socket
Sign inDemoInstall

@material/floating-label

Package Overview
Dependencies
Maintainers
12
Versions
1664
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/floating-label

The Material Components for the web floating-label component


Version published
Weekly downloads
878K
increased by6.73%
Maintainers
12
Weekly downloads
 
Created

Package description

What is @material/floating-label?

@material/floating-label is a package from the Material Components for the Web (MDC Web) library. It provides a floating label component that can be used in form fields to enhance user experience by animating the label when the input field is focused or filled.

What are @material/floating-label's main functionalities?

Basic Floating Label

This code snippet demonstrates how to create a basic floating label using the @material/floating-label package. The label will float above the input field when the field is focused or filled.

<div class="mdc-floating-label" id="my-label-id">My Label</div>

Floating Label with Input

This example shows how to use the floating label in conjunction with an input field. The label will float above the input field when the user interacts with it.

<div class="mdc-text-field">
  <input type="text" class="mdc-text-field__input" aria-labelledby="my-label-id">
  <label class="mdc-floating-label" id="my-label-id">My Label</label>
</div>

JavaScript Initialization

This code demonstrates how to initialize the floating label component using JavaScript. This is useful for adding dynamic behavior to the floating label.

import { MDCFloatingLabel } from '@material/floating-label';

const floatingLabel = new MDCFloatingLabel(document.querySelector('.mdc-floating-label'));

Other packages similar to @material/floating-label

Readme

Source

Floating Label

Floating labels display the type of input a field requires. Every Text Field and Select should have a label, except for full-width text fields, which use the input's placeholder attribute instead. Labels are aligned with the input line and always visible. They can be resting (when a field is inactive and empty) or floating. The label is a text caption or description for the Text Field.

Design & API Documentation

  • Material Design guidelines: Text Fields Layout
  • Demo with Text Field

Basic Usage

HTML Structure

<label class="mdc-floating-label" for="my-text-field-id">Hint text</label>

Styles

@import "@material/floating-label/mdc-floating-label";

JavaScript Instantiation

import {MDCFloatingLabel} from '@material/floating-label';

const floatingLabel = new MDCFloatingLabel(document.querySelector('.mdc-floating-label'));

Variants

Avoid Dynamic ID Generation

If you're using the JavaScript-enabled version of floating label, you can avoid needing to assign a unique id to each <input> by wrapping mdc-text-field__input within a <label>:

<label class="mdc-text-field">
  <input type="text" class="mdc-text-field__input">
  <span class="mdc-floating-label">Hint Text</span>
  <div class="mdc-text-field__bottom-line"></div>
</label>

NOTE: This method also works with <select>.

Style Customization

CSS Classes

CSS ClassDescription
mdc-floating-labelMandatory.
mdc-floating-label--float-aboveIndicates the label is floating in the floating position.
mdc-floating-label--shakeShakes the label.

Sass Mixins

MixinDescription
mdc-floating-label-ink-color($color)Customizes the ink color of the label.
mdc-floating-label-fill-color($color)Customizes the fill color of the label.
mdc-floating-label-shake-keyframes($modifier, $positionY, $positionX, $scale)Generates a CSS @keyframes at-rule for an invalid label shake. Used in conjunction with the mdc-floating-label-shake-animation mixin.
mdc-floating-label-shake-animation($modifier)Applies shake keyframe animation to label.
mdc-floating-label-float-position($positionY, $positionX, $scale)Sets position of label when floating.

MDCFloatingLabel Properties and Methods

Method SignatureDescription
shake(shouldShake: boolean) => voidProxies to the foundation's shake() method.
float(shouldFloat: boolean) => voidProxies to the foundation's float() method.
getWidth() => numberProxies to the foundation's getWidth() method.

Usage Within Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Floating Label 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.

MDCFloatingLabelAdapter

Method SignatureDescription
addClass(className: string) => voidAdds a class to the label element.
removeClass(className: string) => voidRemoves a class from the label element.
getWidth() => numberReturns the width of the label element.

MDCFloatingLabelFoundation

Method SignatureDescription
shake(shouldShake: boolean)Shakes or stops shaking the label, depending on the value of shouldShake.
float(shouldFloat: boolean)Floats or docks the label, depending on the value of shouldFloat.
getWidth() => numberReturns the width of the label element.

Keywords

FAQs

Package last updated on 04 Jun 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc