dom_simplebar.js

import getNodes from './get-nodes';

/**
 * @module simplebar
 * @description Utils to manipulate Gravity Forms internal usage of simplebar.
 *
 */

/**
 * @function reInitChildren
 * @description Re-initializes any child instances of SimpleBar that are used within a given parent element.
 * This may be needed when you have nested SimpleBar instances as you can run into issues
 * with the nested instances having display issues.
 *
 * @since 1.2.10
 *
 * @param {HTMLElement} parentEl The parent element to search within for nested SimpleBar instances.
 *
 * @requires getNodes
 *
 * @return {void}
 *
 * @example
 * import { simpleBar } from "@gravityforms/utils";
 *
 * function Example() {
 *   const parent = getNodes( 'example' )[ 0 ];
 *   simpleBar.reInitChildren( parent );
 * }
 *
 */
const reInitChildren = ( parentEl ) => {
	const SimpleBar = window?.SimpleBar || {};
	if ( ! SimpleBar.instances || ! parentEl ) {
		return;
	}
	getNodes( '[data-simplebar]', true, parentEl, true )
		.forEach( ( i ) => SimpleBar.instances.get( i ) ?? new SimpleBar( i ) );
};

export { reInitChildren };