Input#
The <Input>
component is used in a form in order to retrieve input from the user.
Import#
import { Input, InputField } from 'bumbag'
Usage#
Labels#
If you want to have the label contained within the bounds of the input field, supply the containLabel
prop:
Fields#
You can also use the <InputField>
component, which internally has a FieldWrapper to wrap form controls such as labels, hint text and validation text.
It accepts a combination of Input props and FieldWrapper props.
Default values#
For uncontrolled inputs, set a default value using the defaultValue
prop.
Disabled#
Make the input disabled with the disabled
prop.
Loading#
Show a loading indicator with the isLoading
prop.
Types#
Just like normal <input>
elements, you can specify a type
.
Sizes#
An input can come in different sizes - small
, medium
, large
, or the default.
States#
An input can use different states (as per palette) such as danger
, success
and warning
.
Colors#
Addons#
You can use the Group component to add on stuff to your <Input>
.
Icons#
Note: To use input icons, you will need to follow the instructions to set up icons with Bumbag.
Addons#
Controlled Usage#
The previous examples are examples of uncontrolled usage. To control the value yourself, use a combination of onChange
and value
.
Note: Do not use defaultValue
with controlled inputs!
Accessibility#
Rules#
- The input must have an accessible label specified via the
InputField
component, or anaria-label
/aria-labelledby
prop, or ahtmlFor
/id
label pair.
via an InputField
component
<InputField label="First name" />
via an aria-label
/aria-labelledby
prop
<Input aria-label="First name" />
via a htmlFor
/id
label pair
<Label htmlFor="firstName">First name</Label><Input id="firstName" />
Accessibility#
Patterns#
- If an input is required, then
aria-required
is set totrue
for the input. - If an input is invalid, then
aria-invalid
is set totrue
for the input.
Props#
Input Props#
after
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
autoComplete
string
autoFocus
boolean
Automatically focus on the input
before
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
containLabel
boolean
If the label
prop is supplied, is it contained inside the input?
defaultValue
string | string[]
Default value of the input
disabled
boolean
Disables the input
inputProps
{ unstable_system?: any; top?: string | number | { [key: string]: string }; right?: string | number | { [key: string]: string }; bottom?: string | number | { [key: string]: string }; left?: string | number | { [key: string]: string }; ... 809 more ...; onFocus?: (event: FocusEvent<...>) => void; }
inputRef
((instance: any) => void) | RefObject<any>
label
string
isLoading
boolean
Adds a cute loading indicator to the input field
isRequired
boolean
Makes the input required and sets aria-invalid to true
name
string
Name of the input field
size
"default" | (string & {}) | "small" | "medium" | "large"
Alters the size of the input. Can be "small", "medium" or "large"
mask
string
max
string | number
The maximum (numeric or date-time) value for the input. Must not be less than its minimum (min attribute) value.
maxLength
number
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored.
min
string | number
The minimum (numeric or date-time) value for this input, which must not be greater than its maximum (max attribute) value.
minLength
number
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in UTF-16 code points) that the user can enter. For other control types, it is ignored.
multiple
boolean
This prop indicates whether the user can enter more than one value. This attribute only applies when the type attribute is set to email or file.
palette
string
pattern
string
Regex pattern to apply to the input
placeholder
string
Hint text to display
readOnly
boolean
This prop prevents the user from modifying the value of the input. It is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type (such as button or submit).
spellCheck
boolean
Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked.
step
string | number
Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set.
state
string
State of the input. Can be any color in the palette.
type
string
Specify the type of input.
value
string | number | string[]
Value of the input
onBlur
(event: FocusEvent<HTMLInputElement>) => void
Function to invoke when focus is lost
onChange
(event: FormEvent<HTMLInputElement>) => void
Function to invoke when input has changed
onFocus
(event: FocusEvent<HTMLInputElement>) => void
Function to invoke when input is focused
InputField Props#
addonBefore
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Addon component to the input (before). Similar to the addon components in Input.
addonAfter
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Addon component to the input (after). Similar to the addon components in Input.
inputProps
Pick<BoxProps, "unstable_system" | "top" | "right" | "bottom" | "left" | "children" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | ... 777 more ... | "themeKey"> & LocalInputProps
Additional props for the Input component
orientation
"horizontal" | "vertical"
If addonBefore or addonAfter exists, then the addons will render vertically.
Inherits Input
props
after
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
autoComplete
string
autoFocus
boolean
Automatically focus on the input
before
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
containLabel
boolean
If the label
prop is supplied, is it contained inside the input?
defaultValue
string | string[]
Default value of the input
disabled
boolean
Disables the input
inputRef
((instance: any) => void) | RefObject<any>
label
string
isLoading
boolean
Adds a cute loading indicator to the input field
isRequired
boolean
Makes the input required and sets aria-invalid to true
name
string
Name of the input field
size
"default" | (string & {}) | "small" | "medium" | "large"
Alters the size of the input. Can be "small", "medium" or "large"
mask
string
max
string | number
The maximum (numeric or date-time) value for the input. Must not be less than its minimum (min attribute) value.
maxLength
number
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored.
min
string | number
The minimum (numeric or date-time) value for this input, which must not be greater than its maximum (max attribute) value.
minLength
number
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in UTF-16 code points) that the user can enter. For other control types, it is ignored.
multiple
boolean
This prop indicates whether the user can enter more than one value. This attribute only applies when the type attribute is set to email or file.
palette
string
pattern
string
Regex pattern to apply to the input
placeholder
string
Hint text to display
readOnly
boolean
This prop prevents the user from modifying the value of the input. It is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type (such as button or submit).
spellCheck
boolean
Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked.
step
string | number
Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set.
state
string
State of the input. Can be any color in the palette.
type
string
Specify the type of input.
value
string | number | string[]
Value of the input
onBlur
(event: FocusEvent<HTMLInputElement>) => void
Function to invoke when focus is lost
onChange
(event: FormEvent<HTMLInputElement>) => void
Function to invoke when input has changed
onFocus
(event: FocusEvent<HTMLInputElement>) => void
Function to invoke when input is focused
Inherits FieldWrapper
props
children
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)> | (({ elementProps }: { ...; }) => ReactNode)
description
string | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Sets the description text of the field wrapper.
hint
string | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Sets the bottom hint text of the field wrapper.
isOptional
boolean
Sets the optional flag (and displays optional text) on the field wrapper.
labelType
"label" | "legend"
Sets the label type on the field wrapper.
tooltip
string | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Sets the tooltip of the field wrapper. Can be either a string, or a React component.
tooltipTriggerComponent
ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>
Sets the tooltip trigger component.
validationText
string
Sets the bottom validation text of the field wrapper.
Inherits Box
props
use
string | (ComponentClass<any, any> & { useProps: any; }) | (FunctionComponent<any> & { useProps: any; })
className
string
alignX
"right" | "left" | "center"
alignY
"top" | "bottom" | "center"
variant
string
colorMode
string
overrides
{ useCSSVariables?: boolean; altitudes?: AltitudesThemeConfig; borders?: BordersThemeConfig; borderRadii?: BorderRadiiThemeConfig; ... 95 more ...; Template?: TemplateThemeConfig; }
elementRef
((instance: any) => void) | RefObject<any>
themeKey
string
Theming#
Input#
Input.styles.base
Input.styles.placeholder
Input.Wrapper.styles.base
Input.Spinner.styles.base
InputField#
InputField.styles.base