From 244ad743e37237fc701a56a95bfd1952d1135662 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Apr 2024 13:48:31 +0800 Subject: [PATCH] fix: Slider tooltip should not display when open is false (#48708) --- components/slider/__tests__/tooltip.test.tsx | 30 ++++++++++++-------- components/slider/index.tsx | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/components/slider/__tests__/tooltip.test.tsx b/components/slider/__tests__/tooltip.test.tsx index 36ea1d32b9..69f16cc95b 100644 --- a/components/slider/__tests__/tooltip.test.tsx +++ b/components/slider/__tests__/tooltip.test.tsx @@ -54,25 +54,31 @@ describe('Slider.Tooltip', () => { expect(tooltipProps().open).toBeFalsy(); }); - it('When format equals null, tooltip does not display', async () => { + it('tooltip should not display when formatter is null or open is false', async () => { // https://github.com/ant-design/ant-design/issues/48668 - const { container } = render(); + const { container: container1 } = render( + , + ); + // https://github.com/ant-design/ant-design/issues/48707 + const { container: container2 } = render( + , + ); - const handleEle = container.querySelector('.ant-slider-handle')!; + const handler1 = container1.querySelector('.ant-slider-handle')!; + const handler2 = container2.querySelector('.ant-slider-handle')!; // Enter - fireEvent.mouseEnter(handleEle); + fireEvent.mouseEnter(handler1); + fireEvent.mouseEnter(handler2); await waitFakeTimer(); - expect(tooltipProps().open).toBeFalsy(); + expect(container1.querySelector('.ant-tooltip-open')).toBeFalsy(); + expect(container2.querySelector('.ant-tooltip-open')).toBeFalsy(); // Down - fireEvent.mouseDown(handleEle); + fireEvent.focus(handler1); + fireEvent.focus(handler2); await waitFakeTimer(); - expect(tooltipProps().open).toBeFalsy(); - - // Move(Leave) - fireEvent.mouseLeave(handleEle); - await waitFakeTimer(); - expect(tooltipProps().open).toBeFalsy(); + expect(container1.querySelector('.ant-tooltip-open')).toBeFalsy(); + expect(container2.querySelector('.ant-tooltip-open')).toBeFalsy(); }); }); diff --git a/components/slider/index.tsx b/components/slider/index.tsx index 46a4848865..9dc73f053e 100644 --- a/components/slider/index.tsx +++ b/components/slider/index.tsx @@ -154,7 +154,6 @@ const Slider = React.forwardRef // =============================== Open =============================== const [hoverOpen, setHoverOpen] = useRafLock(); const [focusOpen, setFocusOpen] = useRafLock(); - const activeOpen = hoverOpen || focusOpen; const tooltipProps: SliderTooltipProps = { ...tooltip, @@ -168,6 +167,7 @@ const Slider = React.forwardRef } = tooltipProps; const lockOpen = tooltipOpen ?? legacyTooltipVisible; + const activeOpen = (hoverOpen || focusOpen) && lockOpen !== false; const mergedTipFormatter = getTipFormatter(tipFormatter, legacyTipFormatter);