@@ -49,6 +49,17 @@ type CompositeBarViewProps = CompositeBarProps & {
49
49
collapseItems ?: MenuItem [ ] ;
50
50
} ;
51
51
52
+ function getTime ( ) {
53
+ const now = new Date ( ) ;
54
+ const hours = String ( now . getHours ( ) ) . padStart ( 2 , '0' ) ;
55
+ const minutes = String ( now . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
56
+ const seconds = String ( now . getSeconds ( ) ) . padStart ( 2 , '0' ) ;
57
+ const milliseconds = String ( now . getMilliseconds ( ) ) . padStart ( 3 , '0' ) ;
58
+
59
+ const formattedTime = `${ hours } :${ minutes } :${ seconds } .${ milliseconds } ` ;
60
+ return formattedTime ;
61
+ }
62
+
52
63
const CompositeBarView : FC < CompositeBarViewProps > = ( {
53
64
type,
54
65
items,
@@ -65,9 +76,42 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
65
76
active : multipleTooltipActive ,
66
77
activeIndex,
67
78
lastClickedItemIndex,
79
+ hoverState,
68
80
} = useContext ( MultipleTooltipContext ) ;
69
81
const { compact} = useAsideHeaderContext ( ) ;
70
82
83
+ const handleTransitionRun = React . useCallback < ( e : TransitionEvent ) => void > (
84
+ ( e ) => {
85
+ if ( e . target ) {
86
+ const computedStyle = getComputedStyle ( e . target as HTMLElement ) ;
87
+ const isHovered = computedStyle . transform !== 'none' ;
88
+ console . log ( 'isHovered=' , isHovered , getTime ( ) ) ;
89
+ if ( hoverState !== isHovered ) {
90
+ setMultipleTooltipContextValue ( { hoverState : isHovered } ) ;
91
+ }
92
+ }
93
+ } ,
94
+ [ multipleTooltip , multipleTooltipActive ] ,
95
+ ) ;
96
+
97
+ React . useEffect ( ( ) => {
98
+ if ( ref . current ?. refContainer . current ?. node ) {
99
+ const listNode = ref . current . refContainer . current . node as HTMLElement ;
100
+ // this hack allow to detect hover events on element like browser css engine
101
+ listNode . style . setProperty ( 'transition' , 'transform 0.001ms step-start' ) ;
102
+ listNode . style . setProperty ( 'transition-behavior' , 'allow-discrete' ) ;
103
+ listNode . addEventListener ( 'transitionrun' , handleTransitionRun ) ;
104
+
105
+ return ( ) => {
106
+ listNode . removeEventListener ( 'transitionrun' , handleTransitionRun ) ;
107
+ listNode . style . removeProperty ( 'transition-behavior' ) ;
108
+ listNode . style . removeProperty ( 'transition' ) ;
109
+ } ;
110
+ }
111
+
112
+ return ;
113
+ } , [ ] ) ;
114
+
71
115
React . useEffect ( ( ) => {
72
116
function handleBlurWindow ( ) {
73
117
if ( multipleTooltip && multipleTooltipActive ) {
@@ -91,9 +135,9 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
91
135
! multipleTooltipActive &&
92
136
document . hasFocus ( ) &&
93
137
activeIndex !== lastClickedItemIndex &&
94
- e . clientX <= ASIDE_HEADER_COMPACT_WIDTH
138
+ e . clientX <= ASIDE_HEADER_COMPACT_WIDTH &&
139
+ hoverState
95
140
) {
96
- console . log ( `onTooltipMouseEnter: active=true` ) ;
97
141
setMultipleTooltipContextValue ?.( {
98
142
active : true ,
99
143
} ) ;
@@ -112,16 +156,21 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
112
156
activeIndex ,
113
157
lastClickedItemIndex ,
114
158
setMultipleTooltipContextValue ,
159
+ hoverState ,
115
160
] ,
116
161
) ;
117
162
118
163
const onTooltipMouseLeave = useCallback (
119
164
debounce (
120
165
( ) => {
121
- if ( multipleTooltip && multipleTooltipActive && document . hasFocus ( ) ) {
122
- console . log ( `onTooltipMouseLeave: active=false` ) ;
166
+ if (
167
+ multipleTooltip &&
168
+ ( multipleTooltipActive || ! hoverState ) &&
169
+ document . hasFocus ( )
170
+ ) {
123
171
setMultipleTooltipContextValue ?.( {
124
172
active : false ,
173
+ activeIndex : undefined ,
125
174
lastClickedItemIndex : undefined ,
126
175
} ) ;
127
176
}
@@ -132,15 +181,21 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
132
181
trailing : false ,
133
182
} ,
134
183
) ,
135
- [ multipleTooltip , multipleTooltipActive , setMultipleTooltipContextValue ] ,
184
+ [ multipleTooltip , multipleTooltipActive , setMultipleTooltipContextValue , hoverState ] ,
136
185
) ;
137
186
138
187
const onMouseEnterByIndex = useCallback (
139
188
( itemIndex : number ) =>
140
189
debounce (
141
190
( ) => {
142
- console . log ( `onMouseEnterByIndex: itemIndex=${ itemIndex } ` ) ;
143
191
if ( multipleTooltip && document . hasFocus ( ) ) {
192
+ if ( multipleTooltipActive && ! hoverState ) {
193
+ setMultipleTooltipContextValue ( {
194
+ active : false ,
195
+ activeIndex : undefined ,
196
+ } ) ;
197
+ return ;
198
+ }
144
199
let multipleTooltipActiveValue = multipleTooltipActive ;
145
200
if ( ! multipleTooltipActive && itemIndex !== lastClickedItemIndex ) {
146
201
multipleTooltipActiveValue = true ;
@@ -149,10 +204,8 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
149
204
activeIndex === itemIndex &&
150
205
multipleTooltipActive === multipleTooltipActiveValue
151
206
) {
152
- console . log ( 'onMouseEnterByIndex: skip change' ) ;
153
207
return ;
154
208
}
155
- console . log ( `onMouseEnterByIndex: set active=${ itemIndex } ` ) ;
156
209
setMultipleTooltipContextValue ( {
157
210
activeIndex : itemIndex ,
158
211
active : multipleTooltipActiveValue ,
@@ -171,6 +224,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
171
224
lastClickedItemIndex ,
172
225
activeIndex ,
173
226
setMultipleTooltipContextValue ,
227
+ hoverState ,
174
228
] ,
175
229
) ;
176
230
@@ -181,9 +235,10 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
181
235
ref . current ?. activateItem ( undefined as unknown as number ) ;
182
236
if (
183
237
multipleTooltip &&
184
- ( activeIndex !== undefined || lastClickedItemIndex !== undefined )
238
+ ( activeIndex !== undefined ||
239
+ lastClickedItemIndex !== undefined ||
240
+ ! hoverState )
185
241
) {
186
- console . log ( 'onMouseLeave: deactivate tooltip' ) ;
187
242
setMultipleTooltipContextValue ( {
188
243
activeIndex : undefined ,
189
244
lastClickedItemIndex : undefined ,
@@ -203,6 +258,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
203
258
lastClickedItemIndex ,
204
259
multipleTooltip ,
205
260
setMultipleTooltipContextValue ,
261
+ hoverState ,
206
262
] ,
207
263
) ;
208
264
@@ -239,6 +295,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
239
295
onMouseLeave = { onTooltipMouseLeave }
240
296
>
241
297
< List < CompositeBarItem >
298
+ className = { b ( 'list' , { hover : hoverState } ) }
242
299
ref = { ref }
243
300
items = { items }
244
301
selectedItemIndex = { type === 'menu' ? getSelectedItemIndex ( items ) : undefined }
@@ -249,7 +306,6 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
249
306
filterable = { false }
250
307
sortable = { false }
251
308
renderItem = { ( item , _isItemActive , itemIndex ) => {
252
- // console.log('renderItem: ', itemIndex);
253
309
const itemExtraProps = isMenuItem ( item ) ? { item} : item ;
254
310
const enableTooltip = isMenuItem ( item )
255
311
? ! multipleTooltip
0 commit comments