d2l-polymer-behaviors
Shared Polymer-based behaviors and modules for implementing and consuming web components.
Installation
d2l-polymer-behaviors
can be installed from Bower:
bower install d2l-polymer-behaviors
Usage
Include the webcomponents.js "lite" polyfill (for browsers who don't natively support web components), then import the component or scripts as needed.
Methods
D2L.Dom
// returns null or the closest ancestor that fulfills the specified predicate fxnD2LDom; // gets the composed children (including shadow children & distributed children)D2LDom; // gets the composed parent (including shadow host & insertion points)D2LDom; // returns true/false whether the specified ancestorNode is an ancestor of nodeD2LDom; // browser consistent implementation of HTMLElement.offsetParentD2LDom;
D2L.Dom.Focus
// get the composed active element (i.e. the actual element that has focus)D2LDomFocus; // get first focusable child or descendantD2LDomFocus; // get last focusable child or descendantD2LDomFocus; // get the next focusable child, sibling, etc.D2LDomFocus; // get the previous focusable child, sibling, etc.D2LDomFocus; // get the nearest focusable ancestorD2LDomFocus; // check is focusable (tabindex or white-listed elements)D2LDomFocus;
D2L.Dom.Visibility
// checks DOM visibility (includes inline & computed style of element and ancestors)// ... does not check opacity, elements hidden due to overflow or scrolled out of viewD2LDomVisibility;
D2L.Id
// gets a unique indexed id (for lifetime of page)D2LId;
Behaviors
D2L.PolymerBehaviors.FocusableArrowKeysBehavior
The FocusableArrowKeysBehavior
can be used for managing focus with the arrow keys.
- right/down - focuses next element, or first if currently at the end
- left/up - focuses previous element, or last if currently at beginning
- home - focuses first
- end - focuses last
// include the behaviorbehaviors: D2LPolymerBehaviorsFocusableArrowKeysBehavior { PolymerRenderStatus;}
D2L.PolymerBehaviors.VisibleOnAncestorBehavior
The VisibleOnAncestorBehavior
can be used to show an element when a specified ancestor is being hovered, or a child of the ancestor has the focus. Likewise, the element will be hidden if the specified ancestor is not being hovered and none of its children have the focus. To define a component with this behavior, simply include the styles and behavior as shown in the example below.
The consumer of d2l-example
adds the d2l-visible-on-ancestor-target
class to the desired ancestor that will be the target for mouse and focus events. If the user hovers the target, or focuses any element contained within, d2l-example
will be displayed.
... ...
Usage in Production
In production, it's recommended to use a build tool like Vulcanize to combine all your web components into a single import file. More from the Polymer Docs: Optimize for Production...
Coding styles
See the VUI Best Practices & Style Guide for information on VUI naming conventions, plus information about the EditorConfig rules used in this repo.
Versioning
Commits and PR merges to master will automatically do a minor version bump which will:
- Update the version in
package.json
- Add a tag matching the new version
- Create a github release matching the new version
By using either [increment major] or [increment patch] notation inside your merge message, you can overwrite the default version upgrade of minor to the position of your choice.