Skip to content

Commit

Permalink
fix(Form): Added autoFocus prop on the components used as form fields (
Browse files Browse the repository at this point in the history
…#784)

* fix(Form): Added autoFocus prop on the components used as form fields

* Update src/components/Form/Form.stories.tsx

Co-authored-by: Demetrio Marino <[email protected]>

---------

Co-authored-by: Guido Zoli <[email protected]>
Co-authored-by: Federico Maggi <[email protected]>
Co-authored-by: Demetrio Marino <[email protected]>
  • Loading branch information
4 people authored Jan 7, 2025
1 parent 92cbd58 commit 2b4a048
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/BaseInput/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ export type BaseInputProps = {
*/
className?: string

/**
* autofocus property of the HTMLElement
*/
autoFocus?: boolean

}
2 changes: 2 additions & 0 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Checkbox = <T = never, >({
value,
children = label,
className: classNameProp,
autoFocus,
}: CheckboxProps<T>): ReactElement => {
const className = useMemo(() => classnames([
styles.checkbox,
Expand All @@ -51,6 +52,7 @@ export const Checkbox = <T = never, >({

return (
<AntCheckbox
autoFocus={autoFocus}
className={className}
defaultChecked={isInitiallyChecked}
disabled={isDisabled}
Expand Down
5 changes: 5 additions & 0 deletions src/components/Checkbox/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ export type CheckboxProps<T = never, > = {
children?: ReactNode

className?: string

/**
* autofocus property of the HTMLElement
*/
autoFocus?: boolean
}
2 changes: 2 additions & 0 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const Input = (
onChange,
placeholder,
iconLeft,
autoFocus,
iconRight,
allowClear,
maxLength,
Expand Down Expand Up @@ -165,6 +166,7 @@ export const Input = (
addonBefore={addonBefore}
allowClear={allowClear}
appearance={appearance}
autoFocus={autoFocus}
className={styles.input}
component={AntInput}
defaultValue={inputDefaultValue}
Expand Down
2 changes: 2 additions & 0 deletions src/components/InputNumber/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ export const InputNumber = (
max,
step,
precision,
autoFocus,
}: InputNumberProps) : ReactElement => {
return (
<BaseInput
appearance={appearance}
autoFocus={autoFocus}
className={styles.inputNumber}
component={AntInputNumber}
defaultValue={defaultValue}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ export const Search = <ValueType, >(
inputRef,
iconLeft,
iconRight = defaults.iconRight,
autoFocus,
onChange,
onSelect,
onSearch,
}: SearchProps<ValueType>) : ReactElement => {
return (
<BaseInput <AntAutoCompleteProps<ValueType, SearchItem<ValueType>>>
appearance={appearance}
autoFocus={autoFocus}
className={styles.search}
component={AntAutoComplete}
defaultValue={defaultValue}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Select = <ValueType, >(
allowClear,
options,
inputRef,
autoFocus,
onChange,
onClear,
onSelect,
Expand All @@ -93,6 +94,7 @@ export const Select = <ValueType, >(
<BaseInput <AntSelectProps<ValueType, SelectItem<ValueType>>>
allowClear={allowClear}
appearance={appearance}
autoFocus={autoFocus}
className={className}
component={AntSelect}
defaultValue={defaultValue}
Expand Down
2 changes: 2 additions & 0 deletions src/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export const TextArea = (
minLength,
maxLength,
rows,
autoFocus,
}: TextAreaProps) : ReactElement => {
return (
<BaseInput
allowClear={allowClear}
appearance={appearance}
autoFocus={autoFocus}
component={AntInput.TextArea}
defaultValue={defaultValue}
id={id}
Expand Down

0 comments on commit 2b4a048

Please sign in to comment.