Skip to main content

Conventions

The rules that every bootstrap-ng component follows.

Bootstrap markup, not wrappers

Most components use attribute selectors on the element that Bootstrap styles. The rendered DOM is the same as in Bootstrap's own documentation, so selectors such as .accordion > .accordion-item keep working.

<div bsAlert theme="info">…</div>
<button type="button" bsButton="outline" theme="primary">…</button>
<details bsAccordionItem>…</details>

Themes and variants

Bootstrap 6 replaces color-named classes such as .btn-primary with a variant class and a .theme-* class. bootstrap-ng exposes these as separate variant and theme inputs. The themes are primary, accent, success, danger, warning, info, inverse and secondary.

Signals and two-way binding

Inputs use input() and outputs use output(). State that the user can change, such as whether a collapse is open, is a model(), so you can bind it both ways:

<div bsCollapse [(open)]="filtersOpen">…</div>
<dialog bsDialog [(open)]="editing">…</dialog>

Template references

Components with behavior have an exportAs name. Use a template reference to call their methods:

<button type="button" bsButton (click)="confirm.show()">Delete</button>
<dialog bsDialog #confirm="bsDialog">…</dialog>

Imports

Import single components so that unused ones are removed from your bundle. For quick prototypes, BOOTSTRAP_NG contains everything:

import { BOOTSTRAP_NG } from 'bootstrap-ng';

@Component({
  imports: [BOOTSTRAP_NG],
  …
})

Each component also has its own entry point, named after its folder, such as bootstrap-ng/button or bootstrap-ng/datepicker. Importing from bootstrap-ng gives the same bundle: a component that only lazy routes use is loaded with those routes, not up front.

import { BsButton } from 'bootstrap-ng/button';
import { BsDatepicker } from 'bootstrap-ng/datepicker';

Grouped imports

Components made of several directives also export an array with all of them, so one import covers the whole component:

import { BS_TABS } from 'bootstrap-ng/tabs';

@Component({
  // Same as [BsTabs, BsTab, BsTabContent, BsTabPane]
  imports: [BS_TABS],
  …
})
ArrayEntry pointContains
BS_ACCORDIONbootstrap-ng/accordionBsAccordion, BsAccordionItem, BsAccordionHeader, BsAccordionBody
BS_BREADCRUMBbootstrap-ng/breadcrumbBsBreadcrumb, BsBreadcrumbLink
BS_BUTTON_GROUPbootstrap-ng/button-groupBsButtonGroup, BsButtonToolbar
BS_CAROUSELbootstrap-ng/carouselBsCarousel, BsCarouselItem, BsCarouselPrev, BsCarouselNext, BsCarouselIndicator, BsCarouselPlayPause
BS_COLLAPSEbootstrap-ng/collapseBsCollapse, BsCollapseToggle
BS_DIALOGbootstrap-ng/dialogBsDialog, BsDialogClose
BS_DRAWERbootstrap-ng/dialogBsDrawer, BsDrawerToggle, BsDialogClose
BS_FORMSbootstrap-ngForm controls, field layout and validation directives, except BsTypeahead
BS_LIST_GROUPbootstrap-ng/list-groupBsListGroup, BsListGroupItem
BS_MENUbootstrap-ng/menuBsMenu, BsMenuToggle, BsSubmenu
BS_NAVbootstrap-ng/navBsNav, BsNavLink, BsNavOverflow
BS_PROGRESSbootstrap-ng/progressBsProgress, BsProgressStacked
BS_STEPPERbootstrap-ng/stepperBsStepper, BsStepperItem
BS_TABSbootstrap-ng/tabsBsTabs, BsTab, BsTabContent, BsTabPane
BS_TOASTbootstrap-ng/toastBsToast, BsToastClose

Accessibility

Components set the ARIA roles and states that Bootstrap documents, such as aria-expanded on collapse toggles and role="progressbar" on progress bars. You still give labels: for example, aria-label on icon buttons and progress bars. See Accessibility for keyboard support, focus management and live announcements.