Socket
Socket
Sign inDemoInstall

@material/floating-label

Package Overview
Dependencies
8
Maintainers
14
Versions
1663
Alerts
File Explorer

Advanced tools

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
984K
increased by3.51%
Maintainers
14
Created
Weekly downloads
 

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

Installation

npm install @material/floating-label

Basic Usage

HTML Structure

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

Styles

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

JavaScript Instantiation

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

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

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.
mdc-floating-label--requiredIndicates the label is required and adds an asterisk.

Sass Mixins

MixinDescription
ink-color($color)Customizes the ink color of the label.
fill-color($color)Customizes the fill color of the label.
shake-keyframes($modifier, $positionY, $positionX, $scale)Generates a CSS @keyframes at-rule for an invalid label shake. Used in conjunction with the shake-animation mixin.
shake-animation($modifier)Applies shake keyframe animation to label.
float-position($positionY, $positionX, $scale)Sets position of label when floating.
max-width($max-width)Sets the max width of the label.
float-transition($duration-ms, $timing-function)Customizes the duration and optional timing function for the "float" transition.

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.
setRequired(isRequired: boolean) => voidProxies to the foundation's setRequired() 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.
registerInteractionHandler(eventType: string, handler: EventListener) => voidRegisters an event listener for a given event.
deregisterInteractionHandler(eventType: string, handler: EventListener) => voidDeregisters an event listener for a given event.

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.
setRequired(isRequired: boolean)Styles the label as required, depending on the value of isRequired.
getWidth() => numberReturns the width of the label element.

Keywords

FAQs

Last updated on 23 Feb 2024

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.

Install

Related posts

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