From 5c350a80e2db98a1aedc6409e25bbb886094a3a6 Mon Sep 17 00:00:00 2001
From: Starpuccino <854408292@qq.com>
Date: Sat, 24 Jun 2023 14:20:56 +0800
Subject: [PATCH] fix: Slider disabled status in form (#43142)
* fix slider component disabled status in form
* add test case & update demo
* fix related test cases
---
.../__snapshots__/components.test.tsx.snap | 5 +-
.../__snapshots__/demo-extend.test.ts.snap | 72 +++++++++++++++++++
.../__snapshots__/demo.test.tsx.snap | 53 ++++++++++++++
.../__snapshots__/index.test.tsx.snap | 53 ++++++++++++++
components/form/__tests__/index.test.tsx | 4 ++
components/form/demo/disabled.tsx | 4 ++
components/slider/index.tsx | 5 ++
7 files changed, 193 insertions(+), 3 deletions(-)
diff --git a/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap b/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap
index 1f0efdc6f1..dd7a19889a 100644
--- a/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap
+++ b/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap
@@ -25451,7 +25451,7 @@ exports[`ConfigProvider components Slider configProvider 1`] = `
exports[`ConfigProvider components Slider configProvider componentDisabled 1`] = `
+
,
]
`;
diff --git a/components/form/__tests__/__snapshots__/demo.test.tsx.snap b/components/form/__tests__/__snapshots__/demo.test.tsx.snap
index 002f4bbbf2..66e073c921 100644
--- a/components/form/__tests__/__snapshots__/demo.test.tsx.snap
+++ b/components/form/__tests__/__snapshots__/demo.test.tsx.snap
@@ -2719,6 +2719,59 @@ Array [
+
,
]
`;
diff --git a/components/form/__tests__/__snapshots__/index.test.tsx.snap b/components/form/__tests__/__snapshots__/index.test.tsx.snap
index 4ed21ddfa1..08e9899014 100644
--- a/components/form/__tests__/__snapshots__/index.test.tsx.snap
+++ b/components/form/__tests__/__snapshots__/index.test.tsx.snap
@@ -991,6 +991,59 @@ exports[`Form form should support disabled 1`] = `
+
`;
diff --git a/components/form/__tests__/index.test.tsx b/components/form/__tests__/index.test.tsx
index d14941675b..816307f772 100644
--- a/components/form/__tests__/index.test.tsx
+++ b/components/form/__tests__/index.test.tsx
@@ -21,6 +21,7 @@ import zhCN from '../../locale/zh_CN';
import Modal from '../../modal';
import Radio from '../../radio';
import Select from '../../select';
+import Slider from '../../slider';
import Switch from '../../switch';
import TreeSelect from '../../tree-select';
import Upload from '../../upload';
@@ -1160,6 +1161,9 @@ describe('Form', () => {
+
+
+
);
const { container } = render();
diff --git a/components/form/demo/disabled.tsx b/components/form/demo/disabled.tsx
index 525773bd26..4bc045f309 100644
--- a/components/form/demo/disabled.tsx
+++ b/components/form/demo/disabled.tsx
@@ -9,6 +9,7 @@ import {
InputNumber,
Radio,
Select,
+ Slider,
Switch,
TreeSelect,
Upload,
@@ -109,6 +110,9 @@ const FormDisabledDemo: React.FC = () => {
+
+
+
>
);
diff --git a/components/slider/index.tsx b/components/slider/index.tsx
index 3f342d07bd..1c817e5998 100644
--- a/components/slider/index.tsx
+++ b/components/slider/index.tsx
@@ -5,6 +5,7 @@ import type { SliderRef } from 'rc-slider/lib/Slider';
import React from 'react';
import warning from '../_util/warning';
import { ConfigContext } from '../config-provider';
+import DisabledContext from '../config-provider/DisabledContext';
import type { TooltipPlacement } from '../tooltip';
import SliderTooltip from './SliderTooltip';
import useStyle from './style';
@@ -103,6 +104,7 @@ const Slider = React.forwardRef
range,
className,
rootClassName,
+ disabled,
// Deprecated Props
tooltipPrefixCls: legacyTooltipPrefixCls,
tipFormatter: legacyTipFormatter,
@@ -114,6 +116,8 @@ const Slider = React.forwardRef
} = props;
const { getPrefixCls, direction, getPopupContainer } = React.useContext(ConfigContext);
+ const contextDisabled = React.useContext(DisabledContext);
+ const mergedDisabled = disabled ?? contextDisabled;
const [opens, setOpens] = React.useState({});
const toggleTooltipOpen = (index: number, open: boolean) => {
@@ -238,6 +242,7 @@ const Slider = React.forwardRef
range={mergedRange}
draggableTrack={draggableTrack}
className={cls}
+ disabled={mergedDisabled}
ref={ref}
prefixCls={prefixCls}
handleRender={handleRender}