Files
threshold-ui/addons/rose/addon/modifiers/on-click-inside.js
T
Zhihe Li bcf004b8a4 Reformat codebase with trailing commas in functions (#2006)
* style: 💄 Update trailing commas in API

* style: 💄 Update trailing commas in core

* style: 💄 Update trailing commas in rose

* style: 💄 Update trailing commas in admin

* style: 💄 Update trailing commas in desktop
2023-11-22 14:07:41 -05:00

29 lines
660 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { modifier } from 'ember-modifier';
/**
* Used to detect clicks occurring _inside_ the modified element.
* This is useful especially for dropdowns to toggle content visibility
* when the user clicks an item.
*/
export default modifier(
(element, [callback]) => {
function handleClick(event) {
if (element.contains(event.target)) {
callback(element, event);
}
}
element.addEventListener('click', handleClick, false);
return () => {
element.removeEventListener('click', handleClick, false);
};
},
{ eager: false },
);