TextBox CSS Styling

Smart.TextBox element represents single row editable text box. Supports two display modes.

Required files

Smart.TextBox requires the following scripts to be referenced on a page in order for the custom element to be successfully registered and to work correctly:

  • smart.element.js — this is the base file that defines the common architecture of all Smart custom elements. It is part of the repository ni-kismet/smart-element.
  • smart.button.js — this file defines the functionality of the Smart.Button custom element used inside the Scroll bars.
  • smart.scrollbar.js — this file defines the functionality of the Smart.ScrollBar custom element used inside the ListBox drop down.
  • smart.listbox.js — this file defines the functionality of the Smart.ListBox custom element used inside the drop down.
  • smart.dropdownlist.js — this file defines the functionality of the Smart.DropDownList used as a drop down.
  • smart.combobox.js — this file defines the base class for the Smart.TextBox.
  • smart.textbox.js — this file defines the functionality of the Smart.TextBox custom element.

Smart.TextBox also requires the following style sheet in order to be displayed correctly.

  • smart.base.css — the base style sheet file.

Initialization

To initialize (instantiate) a Smart.TextBox custom element, insert the following tag in an HTML page:

<smart-text-box></smart-text-box>

To set properties of the custom element initially, do so by setting the respective attributes of the tag, e.g.:

<smart-text-box display-mode="escaped"></smart-text-box>

Getting and setting properties dynamically

Before accessing the custom element’s API in JavaScript, the custom element’s instance has to be retrieved:

let customElement = document.querySelector('smart-text-box');

Properties are represented as members of the custom element’s instance object and can be accessed as such.

Here is an example showing how to get a property dynamically:

let displayMode = customElement.displayMode;

Here is an example showing how to set a property dynamically:

customElement.displayMode = 'escaped';

Calling methods

Before accessing the custom element’s API in JavaScript, the custom element’s instance has to be retrieved:

let customElement = document.querySelector('smart-text-box');

Methods are represented as members of the custom element’s instance object and can be accessed as such.

Here is an example showing how to call a method:

customElement.reset();

Styling (CSS API)

Smart HTML Elements use a pair of css files – smart.base.css and smart.[theme name].css. The base stylesheet creates the styles related to the element’s layout like margin, padding, border-width, position. The second CSS file applies the HTML Element’s colors, fonts, borders and backgrounds. The smart.base.css should be included before the second CSS file.

CSS selectors

The following CSS selectors can be used to style Smart.TextBox:

  • smart-text-box – the element itself. Can be used to set width and height for the whole element.
    • .smart-container – the container that holds all of the internals of the element. Shoudn’t be used for styling.
    • .smart-label – an HTML Span element used to hold the label above the element.
    • .smart-content – an HTML Container that holds the input and the drop down elements.
      • Input – an HTML Input element.
    • .smart-drop-down – the drop down elemnt container.
      • smart-list-box – a Smart.ListBox custom element used as the drop down.
    • INPUT element – an HTML Input element used for the user input.
    • .smart-hint – an HTML Span element used to hold the hint below the element.

CSS variables

Smart.TextBox uses the following CSS variables:

  • –smart-text-box-default-width – used to set the default width of the element. Default value is 200px.
  • –smart-text-box-default-height – used to set the default height of the element. Default value is 30px.