TextBox — Smart UI JavaScript API
On this page + Quick start
Quick start · JavaScript
Complete starter source per framework. Run the scaffold/install command first, then replace the listed files with the full code below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TextBox - JavaScript Quick Start</title>
<link rel="stylesheet" href="./node_modules/smart-webcomponents/source/styles/smart.default.css" />
</head>
<body>
<smart-text-box id="demo-textbox"></smart-text-box>
<script type="module">
import './node_modules/smart-webcomponents/source/modules/smart.textbox.js';
const el = document.getElementById('demo-textbox');
if (el) {
el.placeholder = 'Type here...';
el.selectAllOnFocus = true;
el.placeholder = 'smart Text Box';
el.addEventListener('change', (event) => console.log('change:', event.detail || event));
}
</script>
</body>
</html>
For AI tooling
Developer Quick Reference
Component: TextBox Framework: JavaScript Selector: smart-text-box
API counts: 53 properties, 3 methods, 2 events
Common properties: 0, 1, 2, 3, 4, 5
Common methods: close(), open(), reset()
Common events: change, changing
Module hint: smart-webcomponents/source/modules/smart.textbox.js
TextBox is an input field with auto-suggest options.
Class
TextBox
TextBox is an input field with auto-suggest options.
Selector
smart-text-box
Properties
null. This feature is especially useful for ensuring that dropdowns are visible and functional in complex layouts where parent elements limit visibility due to CSS overflow properties.Events
Methods
Properties
animationControls the animation mode for the component. You can retrieve the current mode or assign a new one. Setting this property to 'none' will disable all animations."none" | "simple" | "advanced"
Controls the animation mode for the component. You can retrieve the current mode or assign a new one. Setting this property to 'none' will disable all animations.
Allowed Values
- "none" - animation is disabled
- "simple" - ripple animation is disabled
- "advanced" - all animations are enabled
Default value
"advanced"Examples
Markup and runtime examples for animation:
HTML:
<smart-text-box animation="none"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.animation = "simple";Read the current value:
const el = document.querySelector('smart-text-box');
const animation = el.animation;
autoCompleteSpecifies the autocomplete mode used to filter and display suggestions from the dataSource. The selected autocomplete mode determines how input text is matched against the available items, showing only those entries that meet the criteria—for example, items that start with, contain, or exactly match the user's input. This setting helps control the relevance and behavior of suggestion lists shown to the user while typing."none" | "auto" | "inline" | "manual"
Specifies the autocomplete mode used to filter and display suggestions from the dataSource. The selected autocomplete mode determines how input text is matched against the available items, showing only those entries that meet the criteria—for example, items that start with, contain, or exactly match the user's input. This setting helps control the relevance and behavior of suggestion lists shown to the user while typing.
Allowed Values
- "none" - Auto complete is disabled.
- "auto" - When the input matches one or many items from the dataSource the drop down opens and displays the matched items. The first suggested item is automatically highlighted as selected and becomes the value of the textbox when the combobox loses focus unless the user chooses a different item or changes the character string in the textbox.
- "inline" - When the input matches one or many items from the dataSource the drop down opens and displays the matched items. The first suggested item is automatically highlighted as selected and becomes the value of the textbox when the combobox loses focus unless the user chooses a different item or changes the character string in the textbox. In addition to that a completion helper that appears next to the input cursor in the input. This helper shows the first possible match by completing the input text.
- "manual" - When the input matches one or many items from the dataSource the drop down opens and displays the matched items.
Default value
"manual"Examples
Markup and runtime examples for autoComplete:
HTML:
<smart-text-box auto-complete="auto"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.autoComplete = "manual";Read the current value:
const el = document.querySelector('smart-text-box');
const autoComplete = el.autoComplete;
autoCompleteDelaySpecifies the duration (in milliseconds) to wait after the user stops typing before displaying the dropdown with autocomplete suggestions. This delay helps control how quickly the matching results appear, improving performance and user experience by preventing unnecessary searches while the user is still typing.number
Specifies the duration (in milliseconds) to wait after the user stops typing before displaying the dropdown with autocomplete suggestions. This delay helps control how quickly the matching results appear, improving performance and user experience by preventing unnecessary searches while the user is still typing.
Default value
100Examples
Markup and runtime examples for autoCompleteDelay:
HTML:
<smart-text-box auto-complete-delay="1000"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.autoCompleteDelay = 1100;Read the current value:
const el = document.querySelector('smart-text-box');
const autoCompleteDelay = el.autoCompleteDelay;
autoFocusSpecifies whether the text box should automatically receive keyboard focus when the page loads, allowing users to start typing immediately without clicking inside the box.boolean
Specifies whether the text box should automatically receive keyboard focus when the page loads, allowing users to start typing immediately without clicking inside the box.
Default value
falseExamples
Markup and runtime examples for autoFocus:
HTML attribute:
<smart-text-box auto-focus></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.autoFocus = false;Read the current value:
const el = document.querySelector('smart-text-box');
const autoFocus = el.autoFocus;
dataSourceSpecifies the data source that populates the ComboBox options. The dataSource property accepts multiple types:- 'Array of strings or numbers:' Each item will be displayed as both the label and value of a list item.- 'Array of objects:' Each object should contain properties—such as label (displayed text) and value (item value)—that define the corresponding list item’s display and value.- 'Callback function:' You can provide a function that returns an array of items in either of the above forms. This allows for dynamic or asynchronous data loading.This flexible approach lets you easily integrate static lists, complex objects, or data fetched from external sources into the ComboBox.any
Specifies the data source that populates the ComboBox options. The dataSource property accepts multiple types:
- 'Array of strings or numbers:' Each item will be displayed as both the label and value of a list item.
- 'Array of objects:' Each object should contain properties—such as label (displayed text) and value (item value)—that define the corresponding list item’s display and value.
- 'Callback function:' You can provide a function that returns an array of items in either of the above forms. This allows for dynamic or asynchronous data loading.
This flexible approach lets you easily integrate static lists, complex objects, or data fetched from external sources into the ComboBox.
Examples
Markup and runtime examples for dataSource:
HTML:
<smart-text-box data-source="["item 1", "item 2"]"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dataSource = ["new item 1", "new item 2"];Read the current value:
const el = document.querySelector('smart-text-box');
const dataSource = el.dataSource;
disabledDetermines whether the element is active and interactive (enabled) or inactive and unresponsive to user interactions (disabled). When set to "disabled," the element cannot be focused, clicked, or edited by the user.boolean
Determines whether the element is active and interactive (enabled) or inactive and unresponsive to user interactions (disabled). When set to "disabled," the element cannot be focused, clicked, or edited by the user.
Default value
falseExamples
Markup and runtime examples for disabled:
HTML attribute:
<smart-text-box disabled></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.disabled = false;Read the current value:
const el = document.querySelector('smart-text-box');
const disabled = el.disabled;
displayLoadingIndicatorSpecifies whether a visual indicator (such as a loading spinner or progress bar) will be displayed while filtering data or loading items from a remote source. This helps inform users that a background operation is in progress.boolean
Specifies whether a visual indicator (such as a loading spinner or progress bar) will be displayed while filtering data or loading items from a remote source. This helps inform users that a background operation is in progress.
Default value
falseExamples
Markup and runtime examples for displayLoadingIndicator:
HTML attribute:
<smart-text-box display-loading-indicator></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.displayLoadingIndicator = false;Read the current value:
const el = document.querySelector('smart-text-box');
const displayLoadingIndicator = el.displayLoadingIndicator;
displayMemberSets or retrieves the displayMember property. The displayMember determines which property of each object in the data source collection (defined by the 'dataSource' property) will be used for display purposes in the user interface. By specifying the name of a property here, you control which value from each data source item is shown to users (e.g., displaying a "name" property from a list of user objects).string
Sets or retrieves the displayMember property. The displayMember determines which property of each object in the data source collection (defined by the 'dataSource' property) will be used for display purposes in the user interface. By specifying the name of a property here, you control which value from each data source item is shown to users (e.g., displaying a "name" property from a list of user objects).
Default value
""""Examples
Markup and runtime examples for displayMember:
HTML:
<smart-text-box display-member="label"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.displayMember = "name";Read the current value:
const el = document.querySelector('smart-text-box');
const displayMember = el.displayMember;
displayModeSpecifies the visual presentation of characters within the input field, such as whether the characters are visible as plain text, masked (e.g., as password dots), or formatted in a particular style. This attribute controls how users see the inputted content while typing or reviewing their entries."default" | "escaped"
Specifies the visual presentation of characters within the input field, such as whether the characters are visible as plain text, masked (e.g., as password dots), or formatted in a particular style. This attribute controls how users see the inputted content while typing or reviewing their entries.
Allowed Values
- "default" - Default behavior. Every character is as is.
- "escaped" - Replaces the special characters with their corresponding character codes. For example, line breaks are replace with '
'.
Default value
"default"Examples
Markup and runtime examples for displayMode:
HTML:
<smart-text-box display-mode="escaped"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.displayMode = "default";Read the current value:
const el = document.querySelector('smart-text-box');
const displayMode = el.displayMode;
dropDownAppendToSpecifies the parent container to which the dropdown menu is appended in the DOM. By default, the dropdown is rendered within its original parent element. However, if an ancestor element has restricted overflow (e.g., 'overflow: hidden' or 'overflow: auto'), the dropdown may be clipped and not display correctly. To resolve this, you can set the dropDownAppendTo property to ''body'', the ID of a specific HTML element, or a direct reference to an HTML element. When set, the dropdown will be moved to the specified container in the DOM, ensuring it displays properly regardless of overflow constraints in its ancestors. To restore the dropdown to its original parent, reset this property to null. This feature is especially useful for ensuring that dropdowns are visible and functional in complex layouts where parent elements limit visibility due to CSS overflow properties.any
Specifies the parent container to which the dropdown menu is appended in the DOM. By default, the dropdown is rendered within its original parent element. However, if an ancestor element has restricted overflow (e.g., 'overflow: hidden' or 'overflow: auto'), the dropdown may be clipped and not display correctly. To resolve this, you can set the dropDownAppendTo property to ''body'', the ID of a specific HTML element, or a direct reference to an HTML element. When set, the dropdown will be moved to the specified container in the DOM, ensuring it displays properly regardless of overflow constraints in its ancestors. To restore the dropdown to its original parent, reset this property to null.
This feature is especially useful for ensuring that dropdowns are visible and functional in complex layouts where parent elements limit visibility due to CSS overflow properties.
Examples
Markup and runtime examples for dropDownAppendTo:
HTML:
<smart-text-box drop-down-append-to="body"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownAppendTo = null;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownAppendTo = el.dropDownAppendTo;
dropDownHeightSpecifies the height of the dropdown menu. By default, this property is set to an empty string, which means the dropdown's height will be determined by a CSS variable. To customize the dropdown's height directly, you can assign a specific value (e.g., "200px" or "50%") to this property. Otherwise, leaving it empty enables the component to use the height defined by the associated CSS variable.string | number
Specifies the height of the dropdown menu. By default, this property is set to an empty string, which means the dropdown's height will be determined by a CSS variable. To customize the dropdown's height directly, you can assign a specific value (e.g., "200px" or "50%") to this property. Otherwise, leaving it empty enables the component to use the height defined by the associated CSS variable.
Default value
""Examples
Markup and runtime examples for dropDownHeight:
HTML:
<smart-text-box drop-down-height="auto"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownHeight = 500;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownHeight = el.dropDownHeight;
dropDownMaxHeightDefines the maximum height for the dropdown menu. If no value is set (default is an empty string), the dropdown’s maximum height will be determined by a corresponding CSS variable instead. This allows for dynamic styling via CSS, while still providing the option to specify a fixed maximum height directly through this property.string | number
Defines the maximum height for the dropdown menu. If no value is set (default is an empty string), the dropdown’s maximum height will be determined by a corresponding CSS variable instead. This allows for dynamic styling via CSS, while still providing the option to specify a fixed maximum height directly through this property.
Default value
""Examples
Markup and runtime examples for dropDownMaxHeight:
HTML:
<smart-text-box drop-down-max-height="800"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownMaxHeight = 1000;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownMaxHeight = el.dropDownMaxHeight;
dropDownMaxWidthSpecifies the maximum width of the dropdown menu. By default, this property is set to an empty string, meaning that the dropdown's max-width is determined by a corresponding CSS variable. If a specific value (such as '300px' or '100%') is provided, it will override the CSS variable and directly set the maximum width of the dropdown.string | number
Specifies the maximum width of the dropdown menu. By default, this property is set to an empty string, meaning that the dropdown's max-width is determined by a corresponding CSS variable. If a specific value (such as '300px' or '100%') is provided, it will override the CSS variable and directly set the maximum width of the dropdown.
Default value
""Examples
Markup and runtime examples for dropDownMaxWidth:
HTML:
<smart-text-box drop-down-max-width="500"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownMaxWidth = 800;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownMaxWidth = el.dropDownMaxWidth;
dropDownMinHeightDefines the minimum height of the dropdown menu. By default, this property is set to an empty string (""), which means the minimum height is not explicitly specified in the component and will instead be determined by the value of a related CSS variable. If a specific value (such as "200px" or "2rem") is provided, it will override the CSS variable and set the minimum height of the dropdown directly.string | number
Defines the minimum height of the dropdown menu. By default, this property is set to an empty string (""), which means the minimum height is not explicitly specified in the component and will instead be determined by the value of a related CSS variable. If a specific value (such as "200px" or "2rem") is provided, it will override the CSS variable and set the minimum height of the dropdown directly.
Default value
""Examples
Markup and runtime examples for dropDownMinHeight:
HTML:
<smart-text-box drop-down-min-height="50"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownMinHeight = 150;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownMinHeight = el.dropDownMinHeight;
dropDownMinWidthSpecifies the minimum width of the dropdown menu. By default, this property is set to an empty string, which means the dropdown's minimum width is determined by a corresponding CSS variable. If you provide a specific value (such as '200px' or '20rem'), it will override the CSS variable and set the dropdown's minimum width accordingly.string | number
Specifies the minimum width of the dropdown menu. By default, this property is set to an empty string, which means the dropdown's minimum width is determined by a corresponding CSS variable. If you provide a specific value (such as '200px' or '20rem'), it will override the CSS variable and set the dropdown's minimum width accordingly.
Default value
""Examples
Markup and runtime examples for dropDownMinWidth:
HTML:
<smart-text-box drop-down-min-width="100"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownMinWidth = 90;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownMinWidth = el.dropDownMinWidth;
dropDownOpenModeSpecifies the direction or animation style in which the dropdown menu appears when activated (e.g., opens upwards, downwards, or with a fade effect)."none" | "default" | "auto"
Specifies the direction or animation style in which the dropdown menu appears when activated (e.g., opens upwards, downwards, or with a fade effect).
Allowed Values
- "none" - The drop down can't be opened.
- "default" - The drop down opens when the user clicks on the element
- "auto" - The drop down opens when the element is hovered and closes when not.
Default value
"default"Examples
Markup and runtime examples for dropDownOpenMode:
HTML:
<smart-text-box drop-down-open-mode="auto"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownOpenMode = "default";Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownOpenMode = el.dropDownOpenMode;
dropDownOverlayWhen this property is enabled, opening the element’s dropdown will create a transparent overlay that covers the entire area between the dropdown and the rest of the webpage. This overlay ensures that any clicks outside the dropdown are intercepted by the overlay itself, rather than interacting with underlying DOM elements. As a result, clicking outside the dropdown can be handled consistently—for example, to close the dropdown—without triggering unintended interactions elsewhere on the page.boolean
When this property is enabled, opening the element’s dropdown will create a transparent overlay that covers the entire area between the dropdown and the rest of the webpage. This overlay ensures that any clicks outside the dropdown are intercepted by the overlay itself, rather than interacting with underlying DOM elements. As a result, clicking outside the dropdown can be handled consistently—for example, to close the dropdown—without triggering unintended interactions elsewhere on the page.
Default value
falseExamples
Markup and runtime examples for dropDownOverlay:
HTML attribute:
<smart-text-box drop-down-overlay></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownOverlay = false;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownOverlay = el.dropDownOverlay;
dropDownPlaceholderSpecifies the placeholder text that appears in the dropdown menu when there are no available items to display. This text provides guidance or context to users, indicating that the dropdown is currently empty.string
Specifies the placeholder text that appears in the dropdown menu when there are no available items to display. This text provides guidance or context to users, indicating that the dropdown is currently empty.
Default value
"No Items"Examples
Markup and runtime examples for dropDownPlaceholder:
HTML:
<smart-text-box drop-down-placeholder="No Items"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownPlaceholder = "Empty";Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownPlaceholder = el.dropDownPlaceholder;
dropDownPositionSpecifies the alignment and placement of the dropdown menu relative to its trigger element when the dropdown is opened, allowing you to control where the menu appears on the screen (e.g., above, below, left, or right of the trigger)."auto" | "top" | "bottom" | "overlay-top" | "overlay-center" | "overlay-bottom" | "center-bottom" | "center-top"
Specifies the alignment and placement of the dropdown menu relative to its trigger element when the dropdown is opened, allowing you to control where the menu appears on the screen (e.g., above, below, left, or right of the trigger).
Allowed Values
- "auto" - The position is automatically determines by measuring the available distance around the element for the drop down to open freely without being clipped by the edges of the browser. By default the drop down will try to open below the element. If the available space is not enough for the drop down to appear it will open in one of the following directions, if possible: top, over.
- "top" - The drop down opens above the element.
- "bottom" - The drop down opens under the element.
- "overlay-top" - The drop down opens above and over the element. The bottom edges of the drop down cover the element.
- "overlay-center" - The drop down opens at the center, over the element.
- "overlay-bottom" - The drop down opens under and over the element. The top edges of the drop down cover the element.
- "center-bottom" - The drop down opens at the center, below the element.
- "center-top" - The drop down opens at the center, over the element.
Default value
"auto"Examples
Markup and runtime examples for dropDownPosition:
HTML:
<smart-text-box drop-down-position="top"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownPosition = "bottom";Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownPosition = el.dropDownPosition;
dropDownWidthSpecifies the width of the dropdown menu. By default, this property is set to an empty string (""). When left empty, the dropdown's width is determined by a corresponding CSS variable, allowing for flexible styling through external or theme-based CSS. To explicitly set a custom width, provide a valid CSS width value (e.g., "200px", "50%").string | number
Specifies the width of the dropdown menu. By default, this property is set to an empty string (""). When left empty, the dropdown's width is determined by a corresponding CSS variable, allowing for flexible styling through external or theme-based CSS. To explicitly set a custom width, provide a valid CSS width value (e.g., "200px", "50%").
Default value
""Examples
Markup and runtime examples for dropDownWidth:
HTML:
<smart-text-box drop-down-width="auto"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.dropDownWidth = 500;Read the current value:
const el = document.querySelector('smart-text-box');
const dropDownWidth = el.dropDownWidth;
enterKeyBehaviorDefines how the "Enter" key functions within the application, such as whether it submits a form, inserts a new line, or triggers a specific action, depending on the context."submit" | "clearOnSubmit"
Defines how the "Enter" key functions within the application, such as whether it submits a form, inserts a new line, or triggers a specific action, depending on the context.
Allowed Values
- "submit" - Submits the value.
- "clearOnSubmit" - Submits and clears the value.
Default value
"submit"Examples
Markup and runtime examples for enterKeyBehavior:
HTML:
<smart-text-box enter-key-behavior="newLine"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.enterKeyBehavior = "submit";Read the current value:
const el = document.querySelector('smart-text-box');
const enterKeyBehavior = el.enterKeyBehavior;
escKeyModeSpecifies how the element responds when the Escape key is pressed, such as closing a dialog, dismissing a modal, or performing a custom action."none" | "previousValue" | "clearValue"
Specifies how the element responds when the Escape key is pressed, such as closing a dialog, dismissing a modal, or performing a custom action.
Allowed Values
- "none" - Nothing happens on escape key.
- "previousValue" - The previous value is retrieved.
- "clearValue" - The value is cleared.
Default value
"none"Examples
Markup and runtime examples for escKeyMode:
HTML:
<smart-text-box esc-key-mode="contains"></smart-text-box>
Vanilla JS — prefer #id if multiple widgets exist on the page:
const el = document.querySelector('smart-text-box');
el.escKeyMode = "equals";Read the current value:
const el = document.querySelector('smart-text-box');
const escKeyMode = el.escKeyMode;
formSpecifies the form element with which this element is associated, known as its "form owner." The value of this attribute must be the ID of a string
Specifies the form element with which this element is associated, known as its "form owner." The value of this attribute must be the ID of a