Skip to content

Commit

Permalink
fix(tag-picker): fix TagPicker clear button not work (#1480)
Browse files Browse the repository at this point in the history
fix #1467
  • Loading branch information
simonguo committed Feb 2, 2021
1 parent c7a1194 commit aadcb51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/InputPicker/InputAutosize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface InputAutosizeProps {
}

interface InputAutosizeState {
inputId: string;
inputWidth: number;
}

Expand All @@ -54,12 +55,7 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
onAutosize: PropTypes.func
};
static defaultProps = {
minWidth: 1,
inputId:
'_' +
Math.random()
.toString(36)
.substr(2, 12)
minWidth: 1
};

inputRef: React.RefObject<any>;
Expand All @@ -69,6 +65,11 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
constructor(props) {
super(props);
this.state = {
inputId:
'_' +
Math.random()
.toString(36)
.substr(2, 12),
inputWidth: props.minWidth
};

Expand All @@ -81,6 +82,10 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
return this.inputRef.current;
}

getInputId = () => {
return this.props.inputId || this.state.inputId;
};

componentDidMount() {
this.copyInputStyles();
this.updateInputWidth();
Expand Down Expand Up @@ -135,7 +140,7 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
}

renderStyles() {
const { inputId } = this.props;
const inputId = this.getInputId();
return isIE() ? (
<style
dangerouslySetInnerHTML={{
Expand All @@ -153,10 +158,10 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
className,
placeholder,
inputClassName,
inputStyle,
inputId
inputStyle
} = this.props;

const inputId = this.getInputId();
const sizerValue = [defaultValue, value, ''].reduce((previousValue, currentValue) => {
if (previousValue !== null && previousValue !== undefined) {
return previousValue;
Expand All @@ -178,7 +183,7 @@ class InputAutosize extends React.Component<InputAutosizeProps, InputAutosizeSta
const [htmlInputProps] = partitionHTMLProps(this.props);

htmlInputProps.className = inputClassName;
htmlInputProps.id = inputId;
htmlInputProps.id = inputId || inputId;
htmlInputProps.style = nextInputStyle;

return (
Expand Down
4 changes: 2 additions & 2 deletions src/InputPicker/styles/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
}

.@{ns}picker-tag-wrapper {
padding-right: @dropdown-toggle-padding-right;
margin-right: @dropdown-toggle-padding-right;

.@{ns}picker-cleanable & {
padding-right: @dropdown-toggle-padding-right + @picker-toggle-clean-width;
margin-right: @dropdown-toggle-padding-right + @picker-toggle-clean-width;
}
}

Expand Down

1 comment on commit aadcb51

@vercel
Copy link

@vercel vercel bot commented on aadcb51 Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.