Marigold
Marigold

Application

MarigoldProvider
RouterProvider

Layout

AppLayoutbeta
Aside
Aspect
Breakout
Center
Columns
Container
Grid
Inline
Inset
Scrollable
Split
Stack
Tiles

Actions

ActionBaralpha
Button
Link
LinkButton
ToggleButtonalpha
ToggleButtonGroupalpha

Form

Autocomplete
Calendarupdated
Checkbox
ComboBox
DateField
DatePicker
FileField
Form
Multiselectdeprecated
NumberField
Radio
SearchField
Select
Slider
Switch
TagFieldbeta
TextArea
TextField
TimeField

Collection

SelectList
Tableupdated
Tag

Navigation

Accordion
Breadcrumbs
Pagination
Sidebarbeta
Tabs
TopNavigationbeta

Overlay

ContextualHelp
Dialog
Drawer
Menu
Toastbeta
Tooltip

Content

Badge
Card
Divider
EmptyStatebeta
Headline
Icon
List
Loader
SectionMessage
SVG
Text

Formatters

DateFormat
NumericFormat

Hooks and Utils

cn
cva
extendTheme
parseFormData
useAsyncListData
useListData
useResponsiveValue
useTheme
VisuallyHidden
Components

NumberField

Component for entering numbers.

The <NumberField> component used for capturing numerical input from the user in a form or similar input context. This allows users to input numbers including integers, decimals, and as well as percentages. The component also offers steppers which provides lower interaction costs.

Anatomy

It consists of a label, an input field and a help text. Optional you can also show a help text and stepper buttons for increasing/decreasing values.

Anatomy of number field

Appearance

The appearance of a component can be customized using the variant and size props. These props adjust the visual style and dimensions of the component, available values are based on the active theme.

The selected theme does not has any options for"variant" and "size".
PropertyTypeDescription
variant-The available variants of this component.
size-The available sizes of this component.

Usage

<NumberField> is an input field that accepts only numeric input.

Use Steppers

The stepper buttons make it easier and faster for people to make small numeric changes. It allows people to increase or decrease a number with a single button press, or by typing the number in the field.

Hide steppers

If you don't want the step buttons to appear, you can easily remove these with the hideStepper property.

Also keep in mind using the width property is essential to provide a good user experience. So each input field shouldn't be larger than the expected content. For example when using stepper buttons it is better to have shorter fields, so that the user can easier reach these buttons (lower interaction costs).

Confirm Guests

Who's going on your trip?
import { Headline, NumberField, Stack, Text } from '@marigold/components';export default () => (  <Stack space={5}>    <div>      <Headline level={3}>Confirm Guests</Headline>      <Text>Who's going on your trip?</Text>    </div>    <NumberField      defaultValue={3}      minValue={0}      maxValue={20}      width="1/6"      label="Adults"    />    <NumberField      defaultValue={0}      minValue={0}      maxValue={20}      width="1/6"      label="Children"    />    <NumberField      defaultValue={0}      minValue={0}      maxValue={20}      width="1/6"      label="Infants"    />  </Stack>);
Do

Use steppers to make small numeric changes, else the interaction cost would be high.

Use Format Options

With <NumberField> you can use Intl.NumberFormatOptions which comes in handy to format the numbers in a certain format, e.g. percent,unit, decimal and currency.

For a full list of supported options, see corresponding MDN Docs. A full list of suported units can be seen here.

import { NumberField, Stack } from '@marigold/components';export default () => (  <Stack space={4}>    <NumberField      label="Amount"      defaultValue={19.99}      formatOptions={{        style: 'currency',        currency: 'USD',      }}    />    <NumberField      label="Decimals"      formatOptions={{        signDisplay: 'exceptZero',        minimumFractionDigits: 1,        maximumFractionDigits: 2,      }}      step={0.1}      defaultValue={0}    />    <NumberField      label="Length"      defaultValue={150}      minValue={0}      formatOptions={{        style: 'unit',        unit: 'centimeter',        unitDisplay: 'short',      }}    />    <NumberField      label="Percentage"      defaultValue={0.42}      formatOptions={{        style: 'percent',      }}    />  </Stack>);
Do

In addition, use units to support the label and make it clear what the user is entering in a particular number field.

Label

In general label should be short and precise about what is expected from the user. Avoid unnecessary instructional verbs (doing words) in your labels and hints because it's already implied by the input field. Avoid placeholder text in most cases, as there's no need for it (more about it in the next section).

Do
Do: Use short labels
Use short labels.
Don't
Don't use unnecessary instructional verbs

Don't use unnecessary instructional verbs.

Placeholder

Placeholder text is a short hint displayed inside an input field before a user enters a value. To save space, placeholder text is often used instead of a label, as shown in the first example. This is problematic for the following reasons:

  • Placeholder text disappears once a person starts filling in an input field, causing some to forget what the field was for
  • Some might miss or skip fields with placeholder text, as it can look like the field has already been pre-filled.
  • Placeholder text colour contrast is almost always inaccessible, as it's very light by design. This means many will struggle to read the label.
Do
Do: Use label instead of a placeholder
Use label instead of a placeholder.
Don't
Don't use placeholder text instead of a label

Don't use placeholder text instead of a label.

Additional Description

Sometimes the label isn't enough for the user. In this case, to gather additional support for the user we can use the help text. With this we can add helpful hints for the user below the input field. Beside that the help text is placed in close proximity to the associated input field.

Do
Do: Use help text to show an example what's expected

Use help text to show an example what's expected.

Do
Do: Explain why certain information is needed
Explain why certain information is needed.

NumberField With An Error

Error messages should let people know that a problem occurred, why it happened, and provide a solution to fix it and move forward.

Don't
Don't: Never blame the user

Never blame the user. Always be positive and helpful.

Don't
Don't: Be concise and avoid unnecessary words

Be concise and avoid unnecessary words like "please", "sorry" and "oops"

Do
Do: Use detailed messages instead of global messages

Use detailed messages instead of global messages.

The error prop toggles the error state of a field. The errorMessage prop can then be used to provide feedback to the user about the error. The message disappears automatically when all requirements are met.

The charge is not allowed to be more than 1.000 €
import { useState } from 'react';import { NumberField } from '@marigold/components';export default () => {  const [charge, setCharge] = useState<number>(9999);  const errors: string[] = [];  if (charge > 1000) {    errors.push('The charge is not allowed to be more than 1.000 €');  }  return (    <NumberField      label="Charge"      value={charge}      formatOptions={{        style: 'currency',        currency: 'EUR',      }}      minValue={0}      error={errors.length > 0}      errorMessage={errors}      onChange={setCharge}      hideStepper    />  );};

Note

Press Enter, after typing your text, to trigger the validation.

Props

Did you know? You can explore, test, and customize props live in Marigold's storybook. Watch the effects they have in real-time!
View NumberField stories

NumberField

Prop

Type

Related

Form developement guide

This page should introduce you on how to build forms with Marigold.

Intl.NumberFormat

Enables language-sensitive number formatting.

NumericFormat

Helper component for formatting numeric based on the current language and locale-specific conventions.
Last update: 17 days ago

Multiselect

A text-field that allows the user to select multiples values from a provided items array.

Radio

Component which allows to select only one option from a list.

On this page

AnatomyAppearanceUsageUse SteppersUse Format OptionsLabelPlaceholderAdditional DescriptionNumberField With An ErrorPropsNumberFieldRelated