Date Picker

Renders an input with label and error messages.

Read more Read less

A Phoenix.HTML.FormField may be passed as argument, which is used to retrieve the input name, id, and values. Otherwise all attributes may be passed explicitly.

Types

This function accepts all HTML input types, considering that:

  • You may also set type="select" to render a <select> tag
  • For live file uploads, see Phoenix.Component.live_file_input/1

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input for more information. Unsupported types, such as hidden and radio, are best written directly in your templates.

Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />

# Password input with visibility toggle
<.input type="password" name="password" label="Password" />

# The label can be also passed as a custom_label slot (for checkbox, radio, and toggle only)
<.input type="checkbox" name="terms">
  <:custom_label>Accept <.a href="#">terms and conditions</.a></:custom_label>
</.input>

# Password input with help text
<.input type="password" name="password" label="Password">
  <:help>Password must be at least 8 characters long</:help>
</.input>

Accessibility Features

Password Input

  • aria-describedby - Links input with toggle button
  • aria-label - Provides context for the toggle button
  • aria-pressed - Indicates toggle state
  • aria-controls - Associates toggle with input field

Security Features

Password Input

  • Auto-hide password after 5 seconds when revealed
  • autocomplete="current-password" for secure browser password management
<div id="date-picker-single-basic-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-basic"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
    />
  </form>
</div>
<div id="date-picker-single-with-different-min-and-max-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-different-min-and-max"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      min_date={~D[2026-01-01]}
      max_date={~D[2028-10-31]}
    />
  </form>
</div>
<div id="date-picker-single-with-more-than-3-years-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-more-than-3-years"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      min_date={~D[2026-01-01]}
      max_date={~D[2029-10-31]}
    />
  </form>
</div>
<div id="date-picker-single-with-range-in-past-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-range-in-past"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      min_date={~D[2021-01-01]}
      max_date={~D[2023-10-31]}
    />
  </form>
</div>
<div id="date-picker-single-with-placeholder-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-placeholder"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      placeholder="MM/DD/YYYY"
    />
  </form>
</div>
<div id="date-picker-single-with-required-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-required"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      required
      placeholder="MM/DD/YYYY"
    />
  </form>
</div>
Selected date: 1/14/2026
<div id="date-picker-single-with-value-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-value"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      value={~D[2026-01-14]}
      placeholder="MM/DD/YYYY"
    />
  </form>
</div>

Invalid date

<div id="date-picker-single-with-error-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-error"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      errors={["Invalid date"]}
      placeholder="MM/DD/YYYY"
    />
  </form>
</div>
<div id="date-picker-single-with-custom-change-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-custom-change"
      label="Trip Date"
      name="trip_date"
      type="live_date_picker"
      placeholder="MM/DD/YYYY"
      phx-change="custom_change"
    />
  </form>
</div>
<.input
  id="date-picker-single-with-parent-form"
  label="Trip Date"
  name="trip_date"
  type="live_date_picker"
/>
<div id="date-picker-single-with-position-left-storybook-wrapper" style="width: 100%; height: 500px;">
  <form>
    <.input
      id="date-picker-single-with-position-left"
      label="Trip Date"
      name="trip_date"
      position="left"
      type="live_date_picker"
    />
  </form>
</div>