Popout site navigation panel, a standards-based DOM Component
npm install rwt-sitenav

##### Open Source DOM Component
by Read Write Tools | Abstract |
|---|
| The rwt-sitenav DOM component is a pull-out website navigation menu, with subtle hamburger button, and default activation of the menu item for the current page. |
Sometimes you need to provide your website visitors with quick access to a large
quantity of pages without cluttering the main reading area of the page.
The rwt-sitenav DOM component does this by keeping the menu
off the left-hand side of the page until the user needs it. The menu is
activated, sliding over the page content, when the user clicks on the hamburger
menu button. Activation may also be initiated through the component's toggleMenu
method or through its event interface.
The component has these features:
* The hamburger menu button is subtly displayed along the left-hand margin,
appearing brighter on hover.
* The first few times that a visitor interacts with your website, the menu button
pulses to draw attention to itself.
* The menu scrolls vertically, accommodating any number of menu items.
* Menu items may be kept separate from the DOM component, allowing the webmaster
to change its contents in a single centralized place. Alternatively, menu items
may be slotted directly between the component's opening and closing tags.
* The menu item corresponding to the current page is highlighted and scrolled into
view when the page is first loaded.
* The menu has an event interface for showing and hiding itself.
* The menu emits a custom event to close sibling menus and dialog boxes.
* A keyboard listener is provided to allow a shortcut key to open/close the menu.
#### In the wild
To see an example of this component in use, visit the BLUEFIDDLE
website and press F1 "Menu". To understand what's going on under the
hood, use the browser's inspector to view the HTML source code and network
activity, and follow along as you read this documentation.
#### Prerequisites
The rwt-sitenav DOM component works in any browser that
supports modern W3C standards. Templates are written using BLUE
PHRASE notation, which can be compiled into HTML using the free Read Write View
desktop app. It has no other prerequisites. Distribution and installation are
done with either NPM or via Github.
#### Download
OPTION 1: Familiar with Node.js and the OPTION 2: No prior experience using NPM? Important note: This DOM component uses Node.js and NPM and
Download using NPM
package.json file?
Great. Install the component with this command:
npm install rwt-sitenav
Just follow these general steps:
package.json file in the root of your web project using the command:
npm init
npm install rwt-sitenav
package.json as a convenient distribution and installation mechanism. The DOM component itself does not need them.
If you prefer using Github directly, simply follow these steps:
Download using Github
node_modules directory in the root of your web project.
git clone https://github.com/readwritetools/rwt-sitenav.git
After installation, you need to add two things to your HTML page to make use of
it.
* Add a script tag to load the component's rwt-sitenav.js file:
``html`
* Add the component tag somewhere on the page.
* For scripting purposes, apply an id attribute.sourceref
* Apply a attribute with a reference to an HTML file containing theshortcut
menu's text and any CSS it needs.
* Optionally, apply a attribute with something like F9, F10, etc. forrole=navigation
hotkey access.
* For WAI-ARIA accessibility apply a attribute.sourceref
* For simple menus, the may be omitted and the menu hyperlinks may be
slotted into the DOM component. Simply place the hyperlinks directly between the and tags.`html`
#### Menu template
The content and format of the menu is not prescribed. You may add hyperlinks
with formatting that matches your website. Still, one important guideline to
keep in mind is that the text of each menu item should be short so that it
doesn't wrap into multiple lines. If necessary, the width of the panel can be
adjusted using the component's --width CSS variable.
The easiest way to start building your menu is to follow this pattern, which
uses list items li for individual pages, and headings h2 for grouping similar
pages.
#### Self identification
The menu item corresponding to the current page can be highlighted when it
identifies itself to the menu. This is accomplished by adding a meta tag to thehttps://example.com:443/services.html
page that contains the short-form URL of the page itself. For example, if the
page's full URL is the shortform URL would/services.html
be .
The short-form URL may be added to any of three special-purpose meta tags, like
this:
`html`
The three items correspond to the artificial hierarchical depth of the menu
items. When the page is first loaded, the DOM component uses the content
attribute of these meta tags as search terms, looking for the menu item with a
matching anchor href. When found, that menu item is highlighted and scrolled
into view.
The search for a corresponding href is conducted starting with the deepestsitenav:level3
level, going from to sitenav:level2 to sitenav:level1.
Continuing with the previous example, if the current page is https://example.com:443/services.html
, then this menu item will be highlighted:
`html`Services
#### Menu size and position
When visible, the menu is absolutely positioned along the left-hand side of the
viewport. Its position and size may be overridden using CSS by defining new
values for the top, bottom, and width variables.
`css`
rwt-sitenav {
--top: 0;
--bottom: 0;
--width: 15.5rem;
--z-index: 1;
}
#### Menu color scheme
The default color palette for the menu uses a dark mode theme. You can use CSS
to override the variables' defaults:
`css``
rwt-sitenav {
--background: var(--nav-black);
--level1-color: var(--title-blue);
--level2-color: var(--pure-white);
--accent-color: var(--yellow);
--accent-background: var(--pure-black);
}
The component issues life-cycle events.
component-loadedwaitOnLoading() method which returns a promise that resolves when the component-loaded event is received. Call this asynchronously with await.The menu can be controlled with its event interface.
toggle-sitenavdocument for toggle-sitenav messages. Upon receipt it will show or hide the menu.keydowndocument for keydown messages. If the user presses the configured shortcut key (F9, F10, etc) it will show/hide the menu. The Esc key hides the menu.collapse-popupdocument for collapse-popup messages, which are sent by sibling menus or dialog boxes. Upon receipt it will close itself.clickdocument for click messages. When the user clicks anywhere outside the menu, it closes itself.---
| Documentation | READ WRITE HUB | |
| Source code | github | |
| Component catalog | DOM COMPONENTS | |
| Package installation | npm | |
| Publication venue | READ WRITE STACK |
The rwt-sitenav DOM component is licensed under the MIT
License.

Copyright © 2020 Read Write Tools. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT License