Skip to content

Commit

Permalink
feature: add option to remove event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker committed Dec 18, 2024
1 parent 069b273 commit 62335e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type ModalProps = {
buttonTriggers?: {
selector: string;
mode: SearchModes;
removeListeners?: boolean;
}[];
showFloatingButton?: boolean;
floatingButtonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
Expand Down
15 changes: 15 additions & 0 deletions clients/search-component/src/utils/hooks/setClickTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ import { useModalState } from "./modal-context";
export const setClickTriggers = () => {
const { setOpen, setMode, props } = useModalState();

function removeAllClickListeners(selector: string) {
const element: Element | null = document.querySelector(selector);
if (!element) return;
// Vue click attributes
element.removeAttribute("@click.prevent");
element.removeAttribute("@click");

const newElement = element.cloneNode(true);
element?.parentNode?.replaceChild(newElement, element);
}


props.buttonTriggers?.forEach((trigger) => {
const element = document.querySelector(trigger.selector);
if (element) {
if (trigger.removeListeners ?? true) {
removeAllClickListeners(trigger.selector);
}
element.addEventListener("click", () => {
startTransition(() => {
setMode(trigger.mode);
Expand Down
1 change: 1 addition & 0 deletions server/src/handlers/page_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub struct OpenGraphMetadata {
pub struct ButtonTrigger {
selector: String,
mode: String,
remove_triggers: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema, Default)]
Expand Down

0 comments on commit 62335e0

Please sign in to comment.