Skip to content
Settings
Theme
Mode

Floating Notch

inputhtmlreactvue

Live

Rendered live with React 19.2.7

floating-notch.tsxplain css only
import './floating-notch.css';

import { useState } from 'react';

interface Props {
  value?: string;
  defaultValue?: string;
  placeholder?: string;
  label?: string;
  disabled?: boolean;
}

export function FloatingNotch({
  value,
  defaultValue = '',
  placeholder = ' ',
  label = 'Email',
  disabled = false,
}: Props) {
  const [internal, setInternal] = useState(defaultValue);
  const current = value ?? internal;

  return (
    <label className="flnt">
      <input
        className="flnt__field"
        type="text"
        placeholder={placeholder}
        value={current}
        disabled={disabled || undefined}
        onChange={(event) => setInternal(event.target.value)}
      />
      <span className="flnt__label">{label}</span>
    </label>
  );
}
dependencies
  • react@19.2.7the dialect you are reading

Built on Astro: the stage mounts the exhibit's actual React or Vue file as a live island. Pick the framework and the stage, the code and the dependency list agree.

The Material outlined field, reduced to its one transition: the label lifts from the resting centre into the top border and its own opaque background cuts the notch open. No legend gymnastics — the label's backdrop is the gap.

The flag honoured here is contrast at rest: the resting label holds 4.5:1 because it is doing a label's job, and muting it to look like a placeholder would fail the field it describes. The placeholder is a single space by contract — :placeholder-shown is the state machine.

v0.25.1