ListBox CSS Styling

Smart.ListBox is a list box that contains items that can be selected by clicking on them. The keyboard can be used to navigate through the items (dependng on the selection mode).

Required files

The Smart.ListBox 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.

Smart.ListBox 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.ListBox custom element, insert the following tag in an HTML page:

<smart-list-box></smart-list-box>

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

<smart-list-box sorted grouped selected-indexes=[2] ></smart-list-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-list-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 sorted = customElement.sorted;

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

customElement.sorted = true;

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

  • smart-list-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.
    • INPUT element – an HTML Input element used for the filter input.
    • .smart-list-items-container – a container for the list items and the placeholder.
      • .smart-placeholder – a placeholder used when no items are present.
      • .smart-list-items-inner-container – a container that holds all list items.
      • INPUT element – a n HTML Input element used when editing items.
    • smart-scroll-bar – a Smart.ScrollBar element used for horizontal scrolling.
    • smart-scroll-bar – a Smart.ScrollBar element used for vertical scrolling.
    • .smart-loader-container – a container for the loading indicator.
      • .smart-loader – the loading indicator.
      • .smart-loader-label – a label for the loading indicator.

CSS variables

Smart.ListBox uses the following CSS variables:

  • –smart-list-box-scroll-bar-size – Used to set the size of the scrollbars (width of the vertical and height of the horizontal). Default value is 20px;
  • –smart-list-box-filter-input-size – Used to set the size(height) of the input field for the filtering. Default value is 25px.
  • –smart-loader-size – used to set the default width and height of the loader. Default value is 30px.