Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the customization of the name of DOM elements when clicked #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/clarity-js/src/interaction/click.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/clarity-js/types/layout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down