Skip to content

Commit dfcc2bc

Browse files
committed
fix(useFloatingWithInteractions): ref for props
Удалил рефы для свойств. Для чего нужны рефы не понял. При переключении типа триггера обработчики сохранялись, что гипотетически могло привести к багам
1 parent 580dbe4 commit dfcc2bc

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

packages/vkui/src/lib/floating/useFloatingWithInteractions/useFloatingWithInteractions.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,67 +321,63 @@ export const useFloatingWithInteractions = <T extends HTMLElement = HTMLElement>
321321
[shownLocalState, shownFinalState, willBeHide, onShownChanged],
322322
);
323323

324-
const referencePropsRef = React.useRef<ReferenceProps>({});
325-
const floatingPropsRef = React.useRef<FloatingProps>({ style: {} });
326-
327-
useIsomorphicLayoutEffect(() => {
328-
referencePropsRef.current = {};
329-
}, [triggerOnHover, triggerOnFocus, triggerOnClick]);
324+
const referenceProps: ReferenceProps = {};
325+
const floatingProps: FloatingProps = { style: {} };
330326

331327
if (shownFinalState) {
332-
floatingPropsRef.current.style = convertFloatingDataToReactCSSProperties({
328+
floatingProps.style = convertFloatingDataToReactCSSProperties({
333329
strategy,
334330
x,
335331
y,
336332
middlewareData,
337333
});
338334

339335
if (disableInteractive) {
340-
floatingPropsRef.current.style.pointerEvents = 'none';
336+
floatingProps.style.pointerEvents = 'none';
341337
}
342338
}
343339

344340
if (triggerOnFocus) {
345-
referencePropsRef.current.onFocus = handleFocusOnReference;
346-
referencePropsRef.current.onBlur = handleBlurOnReference;
341+
referenceProps.onFocus = handleFocusOnReference;
342+
referenceProps.onBlur = handleBlurOnReference;
347343
}
348344

349345
if (triggerOnClick) {
350-
referencePropsRef.current.onClick = handleClickOnReference;
346+
referenceProps.onClick = handleClickOnReference;
351347
}
352348

353349
if (triggerOnHover) {
354-
referencePropsRef.current.onMouseOver = handleMouseEnterOnBoth;
350+
referenceProps.onMouseOver = handleMouseEnterOnBoth;
355351

356352
if (closeAfterClick && !triggerOnClick) {
357-
referencePropsRef.current.onClick = handleClickOnReferenceForOnlyClose;
353+
referenceProps.onClick = handleClickOnReferenceForOnlyClose;
358354
}
359355

360356
if (!disableInteractive) {
361-
floatingPropsRef.current.onMouseOver = handleMouseEnterOnBoth;
357+
floatingProps.onMouseOver = handleMouseEnterOnBoth;
362358
}
363359
}
364360

365361
if (triggerOnHover || triggerOnFocus) {
366-
referencePropsRef.current.onMouseLeave = handleMouseLeaveOnBothForHoverAndFocusStates;
362+
referenceProps.onMouseLeave = handleMouseLeaveOnBothForHoverAndFocusStates;
367363

368364
if (!disableInteractive) {
369-
floatingPropsRef.current.onMouseLeave = handleMouseLeaveOnBothForHoverAndFocusStates;
365+
floatingProps.onMouseLeave = handleMouseLeaveOnBothForHoverAndFocusStates;
370366
}
371367
}
372368

373369
if (shownFinalState) {
374-
floatingPropsRef.current.onAnimationStart = handleFloatingAnimationStart;
375-
floatingPropsRef.current.onAnimationEnd = handleFloatingAnimationEnd;
370+
floatingProps.onAnimationStart = handleFloatingAnimationStart;
371+
floatingProps.onAnimationEnd = handleFloatingAnimationEnd;
376372
}
377373

378374
return {
379375
placement,
380376
shown: shownFinalState,
381377
willBeHide,
382378
refs,
383-
referenceProps: referencePropsRef.current,
384-
floatingProps: floatingPropsRef.current,
379+
referenceProps,
380+
floatingProps,
385381
middlewareData,
386382
onClose: handleOnClose,
387383
// FocusTrap уже определяет нажатие на ESC, поэтому название события содержит конкретный код

0 commit comments

Comments
 (0)