Skip to main content

Text Field

Use cases:

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

Example

$
%

Declaration

<rapid-text-field>Sample Text Field</rapid-text-field>

Usage

@customElement({
name: 'my-element',
template: html`
<div>
<label>Simple text field</label>
<rapid-text-field
:value=${sync((x) => x.fieldValue)}
@change="${(x, ctx) => x.fieldValueChanged(ctx.event)}"
type="text">
</rapid-text-field>
</div>
<div>
<label>Number field with start, end slots and placeholder text</label>
<rapid-text-field
@change="${(x, ctx) => x.fieldValueChanged(ctx.event)}"
type="number">
<div slot="start">$</div>
<div slot="end">$</div>
</rapid-text-field>
</div>
<div>
<label>Disabled text field</label>
<rapid-text-field type="text" disabled>
</rapid-text-field>
</div>
`,
})
export class MyElement extends GenesisElement {
@observable fieldValue = '';
fieldValueChanged() {
console.log(this.fieldValue);
}
}

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.