From 7a9703b6fb43134d9705b6ca500c8d8a4bfa9dae Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 26 May 2023 11:43:16 +0400 Subject: [PATCH] Add `Component.forEachChild` method --- src/dom_components/model/Component.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dom_components/model/Component.ts b/src/dom_components/model/Component.ts index ae4a0d09c..a45a42a6d 100644 --- a/src/dom_components/model/Component.ts +++ b/src/dom_components/model/Component.ts @@ -1804,6 +1804,23 @@ export default class Component extends StyleableModel { return this; } + /** + * Execute a callback function on all inner child components. + * @param {Function} clb Callback function, the child component is passed as an argument + * @example + * component.forEachChild(child => { + * console.log(child) + * }) + */ + forEachChild(clb: (child: Component) => void) { + if (isFunction(clb)) { + this.components().forEach(child => { + clb(child); + child.forEachChild(clb); + }); + } + } + /** * Remove the component * @return {this}