Socket
Socket
Sign inDemoInstall

@material/react-floating-label

Package Overview
Dependencies
15
Maintainers
13
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @material/react-floating-label

Material Components React Floating Label


Version published
Maintainers
13
Install size
763 kB
Created

Readme

Source

React Floating Label

A React version of an MDC Floating Label.

Installation

npm install @material/react-floating-label

Usage

Styles

with Sass:

import '@material/react-floating-label/index.scss';

with CSS:

import '@material/react-floating-label/dist/floating-label.css';

Positioning

React Floating Label is meant to be used with other Components, specifically input type elements. Floating label is positioned absolute, which requires the parent element to be position relative.

Shake Label

To shake the label you'll need to add a ref to the <FloatingLabel /> element. Using the ref, you can then call shake() to start the shake animation. Ex:

import FloatingLabel from '@material/react-floating-label';

class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    // createRef was introduce in React v16.3
    // https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
    this.floatingLabelElement = React.createRef();
  }

  render() {
    return (
      <FloatingLabel ref={this.floatingLabelElement}/>
        My Label
      </FloatingLabel>
    );
  }

  // ... later in code ...

  this.floatingLabelElement.current.shake();
}

Label Width

Label width is set during mount, and is calculated from the offsetWidth property. The Component will call handleWidthChange() when mounted. handleWidthChange() will execute with a new width value if this.props.children changes.

<FloatingLabel
  handleWidthChange={(width) => this.setState({width})}
>
  My Label
</FloatingLabel>

Props

Prop NameTypeDescription
classNameStringClasses to be applied to the root element.
handleWidthChangeFunctionCallback method to pass the width to a parent Component.
floatBooleanFloats label depending on value passed.

Sass Mixins

Sass mixins may be available to customize various aspects of the components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins

Keywords

FAQs

Last updated on 22 Jul 2019

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