ComboBox CSS Styling

Smart.ComboBox element represents an input with a dropdown list of items.

Required files

The Smart.ComboBox element requires the following file references to be placed on a web page in order for the custom element to be successfully registered and properly working:

  • 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. Smart.ScrollBar uses repeat buttons.
  • smart.scrollbar.js -- this file defines the functionality of the Smart.ScrollBar custom element.
  • smart.listbox.js -- this file defines the functionality of the Smart.ListBox custom element used in the Smart.ComboBox.
  • smart.dropdownlist.js -- this file defines the functionality of the Smart.DropDownList custom element. The ComboBox element extends Smart.DropDownList.
  • smart.combobox.js -- this file defines the functionality of the Smart.ComboBox custom element.

Smart.ComboBox also requires the following style sheets in order to be displayed correctly.

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

Initialization

To create an instance of a Smart.ComboBox custom element, insert the following tag in an HTML page:

<smart-combo-box></smart-combo-box>

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

<smart-combo-box drop-down-open-mode="bottom"></smart-combo-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-combo-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 selectedIndexes = customElement.selectedIndexes;

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

customElement.selectedIndexes = [1,2,3];

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.ComboBox:

  • smart-combo-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-selection-field - a container for the input field.
      • INPUT element - an HTML Input element used for the user input.
    • .smart-drop-down-button - an HTML Span element used as a button for the listBox drop down.
    • smart-list-box - Smart.ListBox - the popup. Can be styled like every other Smart.ListBox element.

CSS variables

Smart.ComboBox uses the following CSS variable:

  • --smart-combo-box-default-width - a CSS variable used to set the default width of the element. Default value is 150px.
  • --smart-combo-box-default-height - a CSS variable used to set the default height of the element. Default value is 30px.
  • --smart-drop-down-element-width - a CSS variable used to set the width of the drop down element. Default value is 'auto'.
  • --smart-drop-down-element-height - a CSS variable used to set the height of the drop down element. Default value is 200px.
  • --smart-drop-down-button-width - a CSS variable used to set the width of the drop down element. Default value is 30px.

Animations

By default the animation for the Smart.ComboBox is disabled. It can be enabled by adding the CSS class called "animation" to the element, like so:

<smart-combo-box class="animation"></smart-combo-box>