diff --git a/src/assets/javascripts/component/sidebar/index.ts b/src/assets/javascripts/component/sidebar/index.ts index 1e86cf610..3373753e2 100644 --- a/src/assets/javascripts/component/sidebar/index.ts +++ b/src/assets/javascripts/component/sidebar/index.ts @@ -97,7 +97,7 @@ export function unsetSidebarLock(sidebar: HTMLElement): void { /* ------------------------------------------------------------------------- */ /** - * Create a observable for a sidebar component + * Create an observable for a sidebar component * * @param sidebar - Sidebar element * @param options - Options diff --git a/src/assets/javascripts/ui/element/index.ts b/src/assets/javascripts/ui/element/index.ts index 62377fb44..533ca5a46 100644 --- a/src/assets/javascripts/ui/element/index.ts +++ b/src/assets/javascripts/ui/element/index.ts @@ -23,6 +23,8 @@ import { OperatorFunction, pipe } from "rxjs" import { filter, map } from "rxjs/operators" +import { toArray } from "../../utilities" + /* ---------------------------------------------------------------------------- * Functions * ------------------------------------------------------------------------- */ @@ -42,6 +44,21 @@ export function getElement( return document.querySelector(selector) || undefined } +/** + * Retrieve all elements matching the query selector + * + * @template T - Element type + * + * @param selector - Query selector + * + * @return HTML elements + */ +export function getElements( + selector: string +): T[] { + return toArray(document.querySelectorAll(selector)) +} + /* ------------------------------------------------------------------------- */ /** diff --git a/src/assets/javascripts/utilities/index.ts b/src/assets/javascripts/utilities/index.ts index cb5cfb189..e6115964a 100644 --- a/src/assets/javascripts/utilities/index.ts +++ b/src/assets/javascripts/utilities/index.ts @@ -35,6 +35,6 @@ */ export function toArray< T extends HTMLElement ->(collection: HTMLCollection): T[] { +>(collection: HTMLCollection | NodeListOf): T[] { return Array.from(collection) as T[] }