Skip to main content

Text Field

Use cases:

  • User registration and login
  • Data entry
  • Search boxes
  • Comment sections
  • Search filters

Example​

$
%

Declaration

<TextField></TextField>

Usage

import { TextField } from '@genesislcap/rapid-design-system/react';

export function MyComponent() {

const [textFieldValue, setTextFieldValue] = useState(false);

const handleTextFieldChanged = (event) => {
const target = event.target as HTMLInputElement;
console.log(target.value);
setTextFieldValue(target.value)
};
return (
<div>
<label>Simple text field</label>
<TextField type="text">
</TextField>
</div>
<div>
<label>Number field with start, end slot and placeholder</label>
<TextField onChange={handleTextFieldChanged} type="number" placeholder="Enter text here">
<div slot="start">$</div>
<div slot="end">%</div>
</TextField>
</div>
<div>
<label>Disabled text field</label>
<TextField type="text" disabled>
</TextField>
</div>
);
}

API​

Property and attribute binding examples for Genesis Component syntax.

Attributes​

NameTypeDescriptionExample
autofocusbooleanWhen true, the component will be focused when the page has finished loading
<rapid-text-field ?autofocus="${(x) => x.autoFocus}">
appearancestringCan be outline or filled
<rapid-text-field appearance="outline">
disabledbooleanSimilar to readonly, but with a blur on the component
<rapid-text-field ?disabled="${(x) => x.isDisabled}">
formstringAssociates this component with a form. Form id needs to be passed. If no Id is provided, then it will be associated with the ancestor form
<rapid-text-field form="myForm">
maxlengthnumberThe maximum number of characters allowed
<rapid-text-field maxlength="${(x) => x.maxLength}">
minlengthnumberThe minimum number of characters allowed
<rapid-text-field minlength="${(x) => x.minLength}">
namestringDefines the name of the element
<rapid-text-field name="username">
placeholderstringSets placeholder text for the element (which disappears when the user starts typing)
<rapid-text-field placeholder="Enter your name">
readonlybooleanIf true, the user cannot change the value of this field
<rapid-text-field ?readonly="${(x) => x.isReadonly}">
sizenumberSets the width of the component
<rapid-text-field size="${(x) => x.fieldSize}">
stepnumberOnly works with type="number". Defines the amount the field value changes each time the user clicks to increase or decrease the field value
<rapid-text-field type="number" step="${(x) => x.stepValue}">
typestringSets the type of the text-field. Can be "email" | "password" | "tel" | "number" | "text" | "url".
<rapid-text-field type="email">
valuestringSets the value for this component. Use the sync utility to bind the data the template back to the model.
<rapid-text-field value="${sync((x) => x.fieldValue)}">

Properties​

This component doesn't have any properties which are not also controlled via attributes.

Slots​

SlotUse
startStart slot.
controlThe input element.
endEnd slot.

Example​

Numeric amount using $ symbol in start slot

$
%

Implementation

<rapid-text-field type="text" inputmode="numeric" pattern="\d*">
<div slot="start">
$
</div>
</rapid-text-field>

Parts​

Part
start
control
end

Fired Events​

This component doesn't emit any events.

Listened Events​

This component doesn't listen to any events.

Further details​

This component is an implementation of an HTML text-field element.