diff --git a/src/Slider.tsx b/src/Slider.tsx index 965acc176..44b169f82 100644 --- a/src/Slider.tsx +++ b/src/Slider.tsx @@ -444,7 +444,7 @@ const Slider = React.forwardRef>((prop }, blur: () => { const { activeElement } = document; - if (containerRef.current.contains(activeElement)) { + if (containerRef.current?.contains(activeElement)) { (activeElement as HTMLElement)?.blur(); } }, @@ -513,10 +513,7 @@ const Slider = React.forwardRef>((prop >
>((prop style={trackStyle} values={sortedCacheValues} startPoint={startPoint} - onStartMove={mergedDraggableTrack ? onStartMove : null} + onStartMove={mergedDraggableTrack ? onStartMove : undefined} /> { @@ -189,7 +189,9 @@ describe('Slider', () => { it('decreases the value when key "left" is pressed', () => { const onChange = jest.fn(); const onChangeComplete = jest.fn(); - const { container } = render(); + const { container } = render( + , + ); fireEvent.keyDown(container.getElementsByClassName('rc-slider-handle')[0], { keyCode: keyCode.LEFT, @@ -647,4 +649,9 @@ describe('Slider', () => { fireEvent(document, mouseMove); expect(onChange).toHaveBeenLastCalledWith(100); }); + + it('should render Slider with included=false', () => { + const { asFragment } = render(); + expect(asFragment().firstChild).toMatchSnapshot(); + }); }); diff --git a/tests/__snapshots__/Slider.test.js.snap b/tests/__snapshots__/Slider.test.js.snap index e7163d46d..40af08187 100644 --- a/tests/__snapshots__/Slider.test.js.snap +++ b/tests/__snapshots__/Slider.test.js.snap @@ -28,6 +28,30 @@ exports[`Slider should render Slider with correct DOM structure 1`] = `
`; +exports[`Slider should render Slider with included=false 1`] = ` +
+
+
+
+
+`; + exports[`Slider should render Slider without handle if value is null 1`] = `
{ // // https://github.com/tmpvar/jsdom/commit/0cdb2efcc69b6672dc2928644fc0172df5521176 @@ -366,7 +366,7 @@ describe('Common', () => { 'Warning: [rc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.', ); errSpy.mockRestore(); - }) + }); // Move to antd instead // it('the tooltip should be attach to the container with the id tooltip', () => { diff --git a/tests/marks.test.js b/tests/marks.test.js index 0d8c53c57..deefbdb32 100644 --- a/tests/marks.test.js +++ b/tests/marks.test.js @@ -1,8 +1,8 @@ /* eslint-disable max-len, no-undef */ -import React from 'react'; -import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; -import { render, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; +import { fireEvent, render } from '@testing-library/react'; +import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; +import React from 'react'; import Slider from '../src'; describe('marks', () => {