Skip to content

Commit 92ba45d

Browse files
authored
Merge pull request #2128 from Parvinmh/bugfix/hintAnimation
support data-hint-animation attribute for hintAnimation override
2 parents 66b08bd + 38a302b commit 92ba45d

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/packages/hint/dataAttributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const dataHintAttribute = "data-hint";
22
export const dataStepAttribute = "data-step";
33
export const dataHintPositionAttribute = "data-hint-position";
44
export const dataTooltipClassAttribute = "data-tooltip-class";
5+
export const dataHintAnimationAttribute = "data-hint-animation";

src/packages/hint/hintItem.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe("hintAnimation logic", () => {
2+
const dataHintAnimationAttribute = "data-hint-animation";
3+
4+
let element: HTMLElement;
5+
let hint: { getOption: (key: string) => boolean };
6+
7+
beforeEach(() => {
8+
element = document.createElement("div");
9+
10+
hint = {
11+
getOption: jest.fn(() => true), // default: true
12+
};
13+
});
14+
15+
function getHintAnimation(element: HTMLElement, hint: any): boolean {
16+
const hintAnimationAttr = element.getAttribute(dataHintAnimationAttribute);
17+
let hintAnimation: boolean = hint.getOption("hintAnimation");
18+
if (hintAnimationAttr) {
19+
hintAnimation = hintAnimationAttr === "true";
20+
}
21+
return hintAnimation;
22+
}
23+
24+
test("should use hint.getOption when no attribute is set", () => {
25+
(hint.getOption as jest.Mock).mockReturnValue(true);
26+
27+
const result = getHintAnimation(element, hint);
28+
29+
expect(result).toBe(true);
30+
expect(hint.getOption).toHaveBeenCalledWith("hintAnimation");
31+
});
32+
33+
test("should override with true when attribute is 'true'", () => {
34+
element.setAttribute(dataHintAnimationAttribute, "true");
35+
(hint.getOption as jest.Mock).mockReturnValue(false); // default false
36+
37+
const result = getHintAnimation(element, hint);
38+
39+
expect(result).toBe(true);
40+
});
41+
42+
test("should override with false when attribute is 'false'", () => {
43+
element.setAttribute(dataHintAnimationAttribute, "false");
44+
(hint.getOption as jest.Mock).mockReturnValue(true); // default true
45+
46+
const result = getHintAnimation(element, hint);
47+
48+
expect(result).toBe(false);
49+
});
50+
});

src/packages/hint/hintItem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
dataHintAttribute,
77
dataHintPositionAttribute,
88
dataTooltipClassAttribute,
9+
dataHintAnimationAttribute,
910
} from "./dataAttributes";
1011
import { State } from "../dom";
1112

@@ -69,7 +70,7 @@ export const fetchHintItems = (hint: Hint) => {
6970
//first add intro items with data-step
7071
for (const element of elements) {
7172
// hint animation
72-
let hintAnimationAttr = element.getAttribute(dataHintPositionAttribute);
73+
let hintAnimationAttr = element.getAttribute(dataHintAnimationAttribute);
7374

7475
let hintAnimation: boolean = hint.getOption("hintAnimation");
7576
if (hintAnimationAttr) {

0 commit comments

Comments
 (0)