{"id":21374542,"url":"https://github.com/brightspaceui/d2l-polymer-behaviors-ui","last_synced_at":"2026-01-11T04:05:02.205Z","repository":{"id":38812608,"uuid":"62341156","full_name":"BrightspaceUI/d2l-polymer-behaviors-ui","owner":"BrightspaceUI","description":"Shared Polymer behaviors for use in web components","archived":false,"fork":false,"pushed_at":"2024-05-21T18:11:36.000Z","size":200,"stargazers_count":0,"open_issues_count":0,"forks_count":9,"subscribers_count":18,"default_branch":"main","last_synced_at":"2024-11-15T22:58:38.507Z","etag":null,"topics":["browser","polymer","web-components"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrightspaceUI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-30T20:44:19.000Z","updated_at":"2024-05-21T18:11:38.000Z","dependencies_parsed_at":"2024-05-21T19:53:13.153Z","dependency_job_id":null,"html_url":"https://github.com/BrightspaceUI/d2l-polymer-behaviors-ui","commit_stats":{"total_commits":156,"total_committers":15,"mean_commits":10.4,"dds":0.3717948717948718,"last_synced_commit":"fb16551c44c4c810a82566ef231e080af6fae4d3"},"previous_names":["brightspace/d2l-polymer-behaviors-ui"],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Fd2l-polymer-behaviors-ui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Fd2l-polymer-behaviors-ui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Fd2l-polymer-behaviors-ui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrightspaceUI%2Fd2l-polymer-behaviors-ui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrightspaceUI","download_url":"https://codeload.github.com/BrightspaceUI/d2l-polymer-behaviors-ui/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225869891,"owners_count":17537169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","polymer","web-components"],"created_at":"2024-11-22T08:43:37.808Z","updated_at":"2025-10-09T00:49:16.937Z","avatar_url":"https://github.com/BrightspaceUI.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @brightspace-ui/polymer-behaviors\n\nShared [Polymer](https://www.polymer-project.org/1.0/)-based behaviors and modules for implementing and consuming web components.\n\n## Installation\n\nInstall from NPM:\n\n```shell\nnpm install @brightspace-ui/polymer-behaviors\n```\n\n## Usage\n\n#### Methods\n\n**D2L.Dom**\n\n```javascript\n// returns null or the closest ancestor that fulfills the specified predicate fxn\nD2L.Dom.findComposedAncestor(node, predicate);\n\n// gets the composed children (including shadow children \u0026 distributed children)\nD2L.Dom.getComposedChildren(element);\n\n// gets the composed parent (including shadow host \u0026 insertion points)\nD2L.Dom.getComposedParent(node);\n\n// returns true/false whether the specified ancestorNode is an ancestor of node\nD2L.Dom.isComposedAncestor(ancestorNode, node);\n\n// browser consistent implementation of HTMLElement.offsetParent\nD2L.Dom.getOffsetParent(node);\n```\n\n**D2L.Dom.Focus**\n\n```javascript\n// get the composed active element (i.e. the actual element that has focus)\nD2L.Dom.Focus.getComposedActiveElement();\n\n// get first focusable child or descendant\nD2L.Dom.Focus.getFirstFocusableDescendant(element);\n\n// get last focusable child or descendant\nD2L.Dom.Focus.getLastFocusableDescendant(element);\n\n// get the next focusable child, sibling, etc.\nD2L.Dom.Focus.getNextFocusable(element);\n\n// get the previous focusable child, sibling, etc.\nD2L.Dom.Focus.getPreviousFocusable(element);\n\n// get the nearest focusable ancestor\nD2L.Dom.Focus.getPreviousFocusableAncestor(element);\n\n// check is focusable (tabindex or white-listed elements)\nD2L.Dom.Focus.isFocusable(element);\n```\n\n**D2L.Dom.Visibility**\n\n```javascript\n// checks DOM visibility (includes inline \u0026 computed style of element and ancestors)\n// ... does not check opacity, elements hidden due to overflow or scrolled out of view\nD2L.Dom.Visibility.isVisible(element);\n```\n\n**D2L.Id**\n\n```javascript\n// gets a unique indexed id (for lifetime of page)\nD2L.Id.getUniqueId();\n```\n\n#### Behaviors\n\n**D2L.PolymerBehaviors.FocusableArrowKeysBehavior**\n\nThe `FocusableArrowKeysBehavior` can be used for managing focus with the arrow keys.\n\n* right/down - focuses next element, or first if currently at the end\n* left/up - focuses previous element, or last if currently at beginning\n* home - focuses first\n* end - focuses last\n\n```javascript\n\n// include the behavior\nbehaviors: [\n  D2L.PolymerBehaviors.FocusableArrowKeysBehavior\n],\n\nattached: function() {\n  Polymer.RenderStatus.afterNextRender(this, function() {\n\n    // indicate the direction (default is leftright)\n    this.arrowKeyFocusablesDirection = 'updown';\n\n    // required container element of focusables (used to listen for key events)\n    this.arrowKeyFocusablesContainer = container;\n\n    // required provider method that can return list of focusables - possible async\n    this.arrowKeyFocusablesProvider = function() {\n\n      // simple case\n      return Promise.resolve(focusables);\n\n      // other cases (ex. check visibility when querying focusables)\n      return new Promise(function(resolve) {\n        fastdom.measure(function() {\n          // ...\n          resolve(focusables);\n        });\n      });\n\n    };\n\n    // optional callback before focus is applied\n    this.arrowKeyFocusablesOnBeforeFocus = function(elem) {\n        return new Promise(function(resolve) {\n            // do some stuff\n            resolve();\n        });\n    };\n\n  });\n}\n```\n\n**D2L.PolymerBehaviors.VisibleOnAncestorBehavior**\n\nThe `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.\n\n```html\n\u003cdom-module id=\"d2l-example\"\u003e\n  \u003ctemplate\u003e\n    \u003cstyle include=\"d2l-visible-on-ancestor-styles\"\u003e\u003c/style\u003e\n  \u003c/template\u003e\n  \u003cscript\u003e\n  Polymer({\n    is: 'd2l-example',\n    behaviors: [\n      D2L.PolymerBehaviors.VisibleOnAncestorBehavior\n    ]\n  });\n  \u003c/script\u003e\n\u003c/dom-module\u003e\n```\n\nThe 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.\n\n```html\n\u003cdiv class=\"d2l-visible-on-ancestor-target\"\u003e\n  ...\n  \u003cd2l-example visible-on-ancestor\u003e\u003c/d2l-example\u003e\n  ...\n\u003c/div\u003e\n```\n\n### Versioning and Releasing\n\nThis repo is configured to use `semantic-release`. Commits prefixed with `fix:` and `feat:` will trigger patch and minor releases when merged to `main`.\n\nTo learn how to create major releases and release from maintenance branches, refer to the [semantic-release GitHub Action](https://github.com/BrightspaceUI/actions/tree/main/semantic-release) documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightspaceui%2Fd2l-polymer-behaviors-ui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrightspaceui%2Fd2l-polymer-behaviors-ui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightspaceui%2Fd2l-polymer-behaviors-ui/lists"}