enes

TextBox

The TextBox control lets a user type text into an app. It's typically used to capture a single line of text, but can be configured to capture multiple lines of text. The text displays on the screen in a simple, uniform, plaintext format.

Usage

<script>
	import { TextBox } from 'fluentui-svelte';
</script>

<TextBox type="text" placeholder="Type here..." />

Component API

A brief explanation of the props that really need explaining. You can see the rest of the props here.

Type

The `type` prop specifies the type of input element. It can be set to various types such as `text`, `search`, `email`, `url`, `tel`, `password`, or `number`. This determines the behavior and validation of the input.

Input Element

The `ref` prop allows you to bind a reference to the underlying HTML input element (`bind:ref`). This can be useful for direct DOM manipulations or accessing native input properties. The wrapper element can be bound via `wrapperRef`.

Readonly

The `readonly` prop makes the input field read-only, preventing users from modifying its value. This is useful for displaying information that should not be edited.

Placeholder

The `placeholder` prop sets the placeholder text for the input field, providing a hint to users about what to enter.

Hide Buttons

The `hideActionButtons` prop allows you to hide the extra action buttons in the input, such as clear or submit buttons. This can be useful for a cleaner UI when those actions are not needed.

Query Submitted

The `querySubmitted` event is triggered when a query is submitted, such as when the user presses Enter in a search input. This allows you to handle the submission of the input value.

Text Changed

The `textChanged` event is triggered whenever the content of the text box changes. This can be used to react to user input in real-time, such as validating input or updating other parts of the UI.

On Clear

The `onClear` event is triggered when the input is cleared, allowing you to handle any necessary actions when the user removes the input value.

Component Props

NameTypeDescription
typestringThe type of the input element. Possible values: `'text'`, `'search'`, `'email'`, `'url'`, `'tel'`, `'password'`, `'number'`.
refHTMLInputElementThe DOM reference of the input element.
wrapperRefHTMLDivElementThe DOM reference of the wrapper element.
wrapperAttributesHTMLAttributes<HTMLDivElement>Additional attributes forwarded to the wrapper element.
size'small' | 'medium' | 'large'The size of the input.
readonlybooleanWhether the input is read-only.
placeholderstringThe placeholder text for the input.
hideActionButtonsbooleanWhether to hide the extra action buttons in the input.
justifybooleanWhether the input fills the full width of the container.
contentBeforestring | Snippet | ComponentContent rendered before the input (e.g. an icon).
contentAfterstring | Snippet | ComponentContent rendered after the input (e.g. an icon).
textChanged(e: InputEvent, text: string) => voidEvent triggered when content changes in the text box.
querySubmitted(e: MouseEvent \| KeyboardEvent, query: string) => voidEvent triggered when a query is submitted (Enter or search icon click on `type="search"`).
onClear(e: MouseEvent) => voidEvent triggered when the input is cleared.
childrenSnippetThe children elements to render inside the input.