Angular Nav Component
Documentation and examples of how to use CoreUI Angular navigation components.
Navigation available in CoreUI for Angular share general markup and styles, from the base.nav
class to the activeanddisabled states. Swap modifier classes to switch between each style.
Examples
The basec-nav
component is built with flexbox and provide a strong foundation for building all types of navigationcomponents. It includes some style overrides (for working with lists), some link padding for larger hit areas, andbasic disabled styling.
Base nav
Classes are used throughout, so your markup can be super flexible. Usec-nav-item
like above, or roll your own withac-nav
element. Because the.nav
usesdisplay: flex
, thecNavLink
behaves the same asc-nav-item
would, but without the extra markup.
Change the style ofc-nav
component with modifiers and utilities. Mix and match as needed, or build your own.
Horizontal alignment
Change the horizontal alignment of your nav with flexbox utilities. By default, navs are left-aligned, but you caneasily change them to center or right aligned.Centered with.justify-content-center
:
Right-aligned with.justify-content-end
:
Vertical
Stack your navigation by changing the flex item direction with the.flex-column
utility. Need to stack them on someviewports but not others? Use the responsive versions (ex..flex-sm-column
).
Tabs
Take the basic nav from above and add thevariant="tabs"
class to generate a tabbed interface
Pills
Take that same HTML, but usevariant="pills"
instead:
Underline
Take that same HTML, but usevariant
="underline":
Fill and justify
Force yourc-nav
contents to extend the full available width one of two modifier classes. To proportionately fillall available space with yourc-nav-item
, uselayout="fill"
.Notice that all horizontal space is occupied, but not every nav item has the same width.
For equal-width elements,use layout="justified"
. All horizontal space will be occupied by nav links, but unlike thefill
above, every nav item will be the same width.
Working with flex utilities
If you need responsive nav variations, consider using a series offlexboxutilities. While more verbose, theseutilities offer greater customization across responsive breakpoints. In the example below, our nav will be stacked onthe lowest breakpoint, then adapt to a horizontal layout that fills the available width starting from the smallbreakpoint.
Using dropdowns
Add dropdown menus with a little extra HTML.
Tabs with dropdowns
Pills with dropdowns
Regarding accessibility
If you're using navs to provide a navigation bar, be sure to add arole="navigation"
to the most logical parentcontainer of thec-nav
, or wrap anav
element around the whole navigation. Do not add the role to thec-nav
itself, as this would prevent it from being announced as an actual list by assistive technologies.
Note that navigation bars, even if visually styled as tabs with the.nav-tabs
class, should not be givenrole="tablist"
,role="tab"
orrole="tabpanel"
attributes. These are only appropriate for dynamic tabbed interfaces, as described in the WAI ARIA Authoring Practices. See JavaScript behavior for dynamic tabbed interfaces in this section for an example. Thearia-current
attribute is not necessary on dynamic tabbed interfaces since our JavaScript handles the selected state by addingaria-selected="true"
on the active tab.
API reference
Nav Module
import { NavModule } from '@coreui/angular';@NgModule({ imports: [NavModule,]})export class AppModule() { }
c-nav
component
Inputs
name | description | type | default |
---|---|---|---|
layout | Specify a layout type for component. | fill |justified | undefined |
variant | Set the nav variant to tabs or pills. | tabs |pills |underline | undefined |
c-nav-item
component
cNavLink
directive
Inputs
name | description | type | default |
---|---|---|---|
active | Toggle the active state for the host link. | boolean | undefined |
disabled | Set disabled attr for the host element. | boolean | false |