From 5543e6d19f73af106e68e8386205b00fc59e815d Mon Sep 17 00:00:00 2001 From: Jonathan Hernandez Date: Tue, 7 Nov 2023 13:17:22 -0600 Subject: [PATCH] Grab text using EventData attribute --- packages/clarity-js/src/interaction/click.ts | 7 ++++--- packages/clarity-js/types/layout.d.ts | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/clarity-js/src/interaction/click.ts b/packages/clarity-js/src/interaction/click.ts index 820d1b00..f28563f0 100644 --- a/packages/clarity-js/src/interaction/click.ts +++ b/packages/clarity-js/src/interaction/click.ts @@ -1,6 +1,6 @@ import { BooleanFlag, Constant, Event, Setting } from "@clarity-types/data"; import { BrowsingContext, ClickState } from "@clarity-types/interaction"; -import { Box } from "@clarity-types/layout"; +import { Box, Constant as LayoutConstant } from "@clarity-types/layout"; import { bind } from "@src/core/event"; import { schedule } from "@src/core/task"; import { time } from "@src/core/time"; @@ -89,8 +89,9 @@ function link(node: Node): HTMLAnchorElement { function text(element: Node): string { let output = null; if (element) { - // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement. - let t = element.textContent || (element as HTMLInputElement).value || (element as HTMLImageElement).alt; + let customText = (element as HTMLElement).getAttribute(LayoutConstant.EventData); + // Grab text using "EventData" attribute, or "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement. + let t = customText || element.textContent || (element as HTMLInputElement).value || (element as HTMLImageElement).alt; if (t) { // Replace multiple occurrence of space characters with a single white space // Also, trim any spaces at the beginning or at the end of string diff --git a/packages/clarity-js/types/layout.d.ts b/packages/clarity-js/types/layout.d.ts index 28eba1d1..e5e19189 100644 --- a/packages/clarity-js/types/layout.d.ts +++ b/packages/clarity-js/types/layout.d.ts @@ -80,6 +80,7 @@ export const enum Constant { MaskData = "data-clarity-mask", UnmaskData = "data-clarity-unmask", RegionData = "data-clarity-region", + EventData = "data-clarity-event", Type = "type", Submit = "submit", Name = "name",