Skip to content

Commit

Permalink
fix(color-picker): 选择色值mode的popup隐藏问题 (Tencent#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWeilian authored Jan 21, 2023
1 parent df49fa4 commit c8ddac1
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/color-picker/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, { useState, useRef } from 'react';
import React, { useRef } from 'react';
import { Popup, PopupProps } from '../popup';
import { ColorPickerProps, TdColorContext } from './interface';
import useClassName from './hooks/useClassNames';
import useControlled from '../hooks/useControlled';
import ColorTrigger from './components/trigger';
import ColorPanel from './components/panel/index';
import useClickOutside from '../_util/useClickOutside';
import { colorPickerDefaultProps } from './defaultProps';

const ColorPicker: React.FC<ColorPickerProps> = (props) => {
const baseClassName = useClassName();
const { popupProps, disabled, inputProps, onChange, colorModes, ...rest } = props;
const { overlayClassName, overlayInnerStyle = {}, ...restPopupProps } = popupProps || {};

const [visible, setVisible] = useState(false);
const [innerValue, setInnerValue] = useControlled(props, 'value', onChange);
const triggerRef = useRef<HTMLDivElement>();
const colorPanelRef = useRef();
Expand All @@ -22,7 +20,6 @@ const ColorPicker: React.FC<ColorPickerProps> = (props) => {
placement: 'bottom-left',
expandAnimation: true,
trigger: 'click',
visible,
...restPopupProps,
overlayClassName: [baseClassName, overlayClassName],
overlayInnerStyle: {
Expand All @@ -31,26 +28,16 @@ const ColorPicker: React.FC<ColorPickerProps> = (props) => {
},
};

useClickOutside(
[triggerRef, colorPanelRef],
() => {
setVisible(false);
},
true,
);

return (
<Popup
{...popProps}
onVisibleChange={(v) => setVisible(v)}
content={
!disabled && (
<ColorPanel
{...rest}
disabled={disabled}
value={innerValue}
colorModes={colorModes}
togglePopup={setVisible}
onChange={(value: string, context: TdColorContext) => setInnerValue(value, context)}
ref={colorPanelRef}
/>
Expand Down

0 comments on commit c8ddac1

Please sign in to comment.