Skip to content

Commit

Permalink
Merge pull request #3486 from bettyblocks/feat/set-focus-to-text-inpu…
Browse files Browse the repository at this point in the history
…t-component-PFR-899

feat: set focus to text input component PFR-899
  • Loading branch information
ingmar-stipriaan authored Oct 3, 2024
2 parents fe0e41d + 499736d commit 88985f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const {
actionVariableId: name,
autoComplete,
autoFocus,
disabled,
error,
label,
Expand Down Expand Up @@ -68,6 +69,7 @@
const parsedLabel = useText(label);
const labelText = parsedLabel;
const debouncedOnChangeRef = useRef(null);
const inputRef = useRef();

const { current: labelControlRef } = useRef(generateUUID());

Expand Down Expand Up @@ -209,10 +211,16 @@
handleValidation(validity);
};

const focusHandler = () =>
setTimeout(() => {
inputRef.current.focus();
}, 0);

B.defineFunction('Clear', () => setCurrentValue(''));
B.defineFunction('Enable', () => setIsDisabled(false));
B.defineFunction('Disable', () => setIsDisabled(true));
B.defineFunction('Reset', () => setCurrentValue(useText(value)));
B.defineFunction('Focus', () => focusHandler());

const handleClickShowPassword = () => {
togglePassword(!showPassword);
Expand Down Expand Up @@ -286,11 +294,13 @@
)}
<InputCmp
id={labelControlRef}
inputRef={inputRef}
name={name}
value={currentValue}
type={showPassword ? 'text' : inputType}
multiline={multiline}
autoComplete={autoComplete ? 'on' : 'off'}
autoFocus={!isDev && autoFocus}
rows={rows}
label={labelText}
placeholder={placeholderText}
Expand Down
1 change: 1 addition & 0 deletions src/prefabs/structures/TextInput/options/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const validation = {
}),

autoComplete: toggle('Autocomplete', { value: false }),
autoFocus: toggle('Autofocus', { value: false }),
disabled: toggle('Disabled'),
placeholder: variable('Placeholder'),
helperText: variable('Helper text'),
Expand Down

0 comments on commit 88985f0

Please sign in to comment.