Skip to content

Commit 054c29c

Browse files
[input-examples-to-numeric] Cleaning up redundant states
1 parent 474ea02 commit 054c29c

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

packages/perseus/src/widgets/numeric-input/input-with-examples.tsx

+6-19
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ type Props = {
3636
linterContext: LinterContextProps;
3737
};
3838

39-
type State = {
40-
focused: boolean;
41-
showExamples: boolean;
42-
};
4339
// [LEMS-2411](Jan 2025) Third: This component has been moved to the NumericInput
4440
// folder as we are actively working towards removing the InputNumber widget.
4541
// This comment can be removed as part of LEMS-2411.
@@ -66,10 +62,7 @@ const InputWithExamples = forwardRef<
6662

6763
const context = React.useContext(PerseusI18nContext);
6864
const inputRef = React.useRef<TextInput>(null);
69-
const [state, setState] = React.useState<State>({
70-
focused: false,
71-
showExamples: false,
72-
});
65+
const [inputFocused, setInputFocused] = React.useState<boolean>(false);
7366

7467
useImperativeHandle(ref, () => ({
7568
current: inputRef.current,
@@ -92,7 +85,7 @@ const InputWithExamples = forwardRef<
9285
const _getInputClassName = () => {
9386
let inputClassName =
9487
ApiClassNames.INPUT + " " + ApiClassNames.INTERACTIVE;
95-
if (state.focused) {
88+
if (inputFocused) {
9689
inputClassName += " " + ApiClassNames.FOCUSED;
9790
}
9891
if (className) {
@@ -148,18 +141,12 @@ const InputWithExamples = forwardRef<
148141

149142
const _handleFocus = () => {
150143
onFocus();
151-
setState({
152-
focused: true,
153-
showExamples: true,
154-
});
144+
setInputFocused(true);
155145
};
156146

157147
const _handleBlur = () => {
158148
onBlur();
159-
setState({
160-
focused: false,
161-
showExamples: false,
162-
});
149+
setInputFocused(false);
163150
};
164151

165152
// Display the examples as a string when there are less than or equal to 2 examples.
@@ -175,8 +162,8 @@ const InputWithExamples = forwardRef<
175162
})
176163
.join("\n");
177164

178-
// Display the examples when they are enabled (shouldShowExamples) and the input is focused (showExamples).
179-
const showExamplesTooltip = shouldShowExamples && state.showExamples;
165+
// Display the examples when they are enabled (shouldShowExamples) and the input is focused.
166+
const showExamplesTooltip = shouldShowExamples && inputFocused;
180167

181168
return (
182169
<Tooltip

0 commit comments

Comments
 (0)