Fallback

Renders a value or a fallback value if the value is empty.

Read more Read less

The values nil, "", [] and %{} are treated as empty values.

This component optionally applies a formatter function to non-empty values.

The primary purpose of this component is to enhance accessibility. If a table cell or property list property has no value, an alternative text must be provided for screen readers.

Maturity: Developing

Usage

Render the value of @some_value if it's available, or display the default placeholder otherwise:

<.fallback value={@some_value} />

Apply a formatter function to @some_value if it is not nil:

<.fallback value={@some_value} formatter={&format_date/1} />

Set a custom placeholder and text for screen readers:

<.fallback
  value={@some_value}
  placeholder="n/a"
  accessibility_text="not available"
/>
Mary n/a
Attribute Type Documentation Default Value
accessibility_text :string

The text for the aria-label attribute in case the value is empty.

Read more Read less
"Not set"

This value should be translated to the language in which the rest of the page is displayed.

class :any

Any additional classes to be added.

Read more Read less
[]

Variations of the component should be expressed via modifier attributes, and it is preferable to use styles on the parent container to arrange components on the page, but if you have to, you can use this attribute to pass additional utility classes to the component.

The value can be a string or a list of strings.

formatter :any

A 1-arity function that takes the value and returns the value for

Read more Read less

display. The formatter function is only applied if value is not an empty value.

placeholder :any

The placeholder to render if the value is empty.

Read more Read less
"-"
rest :global

Any additional HTML attributes.

Required value * :any

The value to display. If the value is nil, "", [], %{} or a

Read more Read less

string of only whitespace, before or after formatting, the placeholder is rendered instead.