Skip to content

Adding a new bar

Dialog element comes in two flavours, modal and standard dialog, which both are supported by the library. Modal will be used as a default.

In modal mode focus will be trapped to the bar and interaction with elements outside the bar will be disabled.

TIP

Remember to provide a way to close the bar with keyboard. Even though by default bar will be closed by hitting esc key or clicking outside the bar, adding a dedicated close button to the bar is highly recommended.

Standard dialog

In standard dialog mode bar will open as a fixed element and interaction with elements outside the bar is allowed. This mode can be useful if you plan to keep the bar as a permanent component of your layout.

Note that in standard dialog mode the following exceptions will take place:

  • Overlay shading will not be rendered.
  • permanent setting will have no effect.
  • Bar is not closeable by hitting esc key.
  • Bar will not be closed by clicking outside the bar.
  • Bar will not be closed when another bar is opened with keepOtherBarsOpen: true.
  • Bar will not be closed when Bartender.closeAll() is called without any arguments.

addBar()

ArgumentTypeDefaultDescription
namestringUnique name for the bar
optionsBartenderBarOptions{}Bar options
javascript
bartender.addBar('mobileNav', {
  el: document.querySelector('.mobileNav'),
  position: 'left',
})

Bar options

PropertyTypeDefaultDescription
elstring | elementBar element as selector string or reference to the element.
position'left' | 'right' | 'top' | 'bottom' | 'center''left'Bar position
modalbooleantrueOpen bar as a modal?
overlaybooleantrueShow overlay shading over the content when bar is open?
permanentbooleanfalseBar is not closeable by clicking overlay of pressing esc key.
scrollTopbooleantrueBar will be scrolled to top after opening it.

Modifying bar settings

Bar options can be modified on the fly, except for the el property.

javascript
bartender.getBar('mobileNav').position = 'right'

Released under the MIT License.