Skip to content

Commit

Permalink
fix(controls): allow disable input via controlProps (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored Feb 26, 2024
1 parent b3d4a1d commit 3228dca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/components/controls/TextArea/TextAreaControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {block} from '../../utils/cn';

import type {TextAreaProps} from './TextArea';

type Props = Omit<TextAreaProps, 'autoComplete' | 'onChange'> & {
type Props = Omit<TextAreaProps, 'autoComplete' | 'onChange' | 'controlProps'> & {
onChange: NonNullable<TextAreaProps['onChange']>;
autoComplete?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['autoComplete'];
controlProps: NonNullable<TextAreaProps['controlProps']>;
};

const b = block('text-area');
Expand Down Expand Up @@ -86,13 +87,13 @@ export function TextAreaControl(props: Props) {

return (
<textarea
{...(controlProps as React.InputHTMLAttributes<HTMLTextAreaElement>)}
ref={handleRef as React.Ref<HTMLTextAreaElement>}
{...controlProps}
ref={handleRef}
style={{
...(controlProps as React.InputHTMLAttributes<HTMLTextAreaElement>)?.style,
...controlProps.style,
height: rows ? 'auto' : undefined,
}}
className={b('control', controlProps?.className)}
className={b('control', controlProps.className)}
name={name}
id={id}
tabIndex={tabIndex}
Expand All @@ -108,7 +109,7 @@ export function TextAreaControl(props: Props) {
onKeyDown={onKeyDown}
onKeyUp={onKeyUp}
onKeyPress={onKeyPress}
disabled={disabled}
disabled={disabled ?? controlProps.disabled}
/>
);
}
7 changes: 4 additions & 3 deletions src/components/controls/TextInput/TextInputControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {block} from '../../utils/cn';

import type {TextInputProps} from './TextInput';

type Props = Omit<TextInputProps, 'autoComplete'> & {
type Props = Omit<TextInputProps, 'autoComplete' | 'controlProps'> & {
autoComplete?: React.TextareaHTMLAttributes<HTMLInputElement>['autoComplete'];
controlProps: NonNullable<TextInputProps['controlProps']>;
};

const b = block('text-input');
Expand Down Expand Up @@ -36,7 +37,7 @@ export function TextInputControl(props: Props) {
<input
{...controlProps}
ref={controlRef}
className={b('control', {type: 'input'}, controlProps?.className)}
className={b('control', {type: 'input'}, controlProps.className)}
type={type}
name={name}
id={id}
Expand All @@ -52,7 +53,7 @@ export function TextInputControl(props: Props) {
onKeyDown={onKeyDown}
onKeyUp={onKeyUp}
onKeyPress={onKeyPress}
disabled={disabled}
disabled={disabled ?? controlProps.disabled}
/>
);
}

0 comments on commit 3228dca

Please sign in to comment.