Skip to content

Commit

Permalink
fix: color-picker not support form disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
RedJue committed Nov 21, 2023
1 parent aee10c8 commit 6636942
Show file tree
Hide file tree
Showing 6 changed files with 511 additions and 7 deletions.
12 changes: 7 additions & 5 deletions components/color-picker/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getStatusClassNames } from '../_util/statusUtils';
import { devUseWarning } from '../_util/warning';
import type { ConfigConsumerProps } from '../config-provider/context';
import { ConfigContext } from '../config-provider/context';
import DisabledContext from '../config-provider/DisabledContext';
import useSize from '../config-provider/hooks/useSize';
import type { SizeType } from '../config-provider/SizeContext';
import { FormItemInputContext, NoFormStyle } from '../form/context';
Expand Down Expand Up @@ -104,7 +105,8 @@ const ColorPicker: CompoundedComponent = (props) => {
} = props;

const { getPrefixCls, direction, colorPicker } = useContext<ConfigConsumerProps>(ConfigContext);

const contextDisabled = useContext(DisabledContext);
const mergedDisabled = disabled ?? contextDisabled;
const [, token] = useToken();

const [colorValue, setColorValue] = useColorState(token.colorPrimary, {
Expand All @@ -113,7 +115,7 @@ const ColorPicker: CompoundedComponent = (props) => {
});
const [popupOpen, setPopupOpen] = useMergedState(false, {
value: open,
postState: (openData) => !disabled && openData,
postState: (openData) => !mergedDisabled && openData,
onChange: onOpenChange,
});
const [formatValue, setFormatValue] = useMergedState(format, {
Expand Down Expand Up @@ -219,7 +221,7 @@ const ColorPicker: CompoundedComponent = (props) => {
color: colorValue,
allowClear,
colorCleared,
disabled,
disabled: mergedDisabled,
disabledAlpha,
presets,
panelRender,
Expand All @@ -237,7 +239,7 @@ const ColorPicker: CompoundedComponent = (props) => {
style={styles?.popup}
overlayInnerStyle={styles?.popupOverlayInner}
onOpenChange={(visible) => {
if (popupAllowCloseRef.current && !disabled) {
if (popupAllowCloseRef.current && !mergedDisabled) {
setPopupOpen(visible);
}
}}
Expand All @@ -261,7 +263,7 @@ const ColorPicker: CompoundedComponent = (props) => {
style={mergedStyle}
color={value ? generateColor(value) : colorValue}
prefixCls={prefixCls}
disabled={disabled}
disabled={mergedDisabled}
colorCleared={colorCleared}
showText={showText}
format={formatValue}
Expand Down

0 comments on commit 6636942

Please sign in to comment.