Commit 70068d2
authored
fix: streamline tooltip management and enhance event handling (#254)
This pull request refactors the tooltip management system in
`tooltip_manager.ts` to simplify the logic and improve maintainability.
The most significant changes include removing redundant checks for
tooltip enablement in multiple functions, updating the `showTooltip`
function to accept an `HTMLElement` parameter, and streamlining the
tooltip state update process.
### Refactoring of Tooltip Management:
* **Simplified `attachTooltip` logic**: Removed the redundant
`tooltipsEnabled` check and moved the addition of the `"has-tooltip"`
class to the `showTooltip` function. This reduces duplication and
ensures consistent behavior.
* **Enhanced mutation observer in `attachTooltip`**: Cleaned up the code
for detecting element removal by removing unnecessary conditions and
ensuring the observer disconnects after hiding the tooltip.
### Updates to Tooltip Behavior:
* **Modified `showTooltip` function**: Added an `HTMLElement` parameter
to allow the function to directly manage the tooltip's associated
element, including adding the `"has-tooltip"` class. This centralizes
tooltip activation logic.
* **Streamlined `updateTooltipsState`**: Simplified the logic by only
removing the `"has-tooltip"` class when tooltips are disabled, reducing
unnecessary conditional branches.1 parent 33052b9 commit 70068d2
1 file changed
+23
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 27 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 47 | | |
| 48 | + | |
60 | 49 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 50 | + | |
65 | 51 | | |
66 | 52 | | |
67 | 53 | | |
68 | 54 | | |
69 | 55 | | |
70 | 56 | | |
71 | 57 | | |
72 | | - | |
| 58 | + | |
73 | 59 | | |
74 | 60 | | |
75 | 61 | | |
76 | 62 | | |
77 | 63 | | |
78 | 64 | | |
| 65 | + | |
79 | 66 | | |
80 | 67 | | |
81 | 68 | | |
| |||
125 | 112 | | |
126 | 113 | | |
127 | 114 | | |
128 | | - | |
129 | | - | |
130 | | - | |
| 115 | + | |
131 | 116 | | |
132 | 117 | | |
133 | 118 | | |
| |||
0 commit comments