Skip to content

Commit b7b3a5e

Browse files
authored
[core] fix(InputGroup): right element padding adjusting on update (#3973)
1 parent aea0fd0 commit b7b3a5e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

packages/core/src/components/forms/inputGroup.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ export class InputGroup extends AbstractPureComponent2<IInputGroupProps & HTMLIn
129129
}
130130

131131
public componentDidMount() {
132-
if (this.rightElement != null) {
133-
const { clientWidth } = this.rightElement;
134-
// small threshold to prevent infinite loops
135-
if (Math.abs(clientWidth - this.state.rightElementWidth) > 2) {
136-
this.setState({ rightElementWidth: clientWidth });
137-
}
132+
this.updateInputWidth();
133+
}
134+
135+
public componentDidUpdate(prevProps: IInputGroupProps & HTMLInputProps) {
136+
if (prevProps.rightElement !== this.props.rightElement) {
137+
this.updateInputWidth();
138138
}
139139
}
140140

@@ -149,4 +149,16 @@ export class InputGroup extends AbstractPureComponent2<IInputGroupProps & HTMLIn
149149
</span>
150150
);
151151
}
152+
153+
private updateInputWidth() {
154+
if (this.rightElement != null) {
155+
const { clientWidth } = this.rightElement;
156+
// small threshold to prevent infinite loops
157+
if (Math.abs(clientWidth - this.state.rightElementWidth) > 2) {
158+
this.setState({ rightElementWidth: clientWidth });
159+
}
160+
} else {
161+
this.setState({ rightElementWidth: DEFAULT_RIGHT_ELEMENT_WIDTH });
162+
}
163+
}
152164
}

0 commit comments

Comments
 (0)