Skip to content

Commit

Permalink
Blank TextField and LongTextField (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpospiech authored Jul 25, 2024
1 parent 9957632 commit 6fe2b41
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/uniforms-antd/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ function LongText({ rows = 5, ...props }: LongTextFieldProps) {
<TextArea
disabled={props.disabled}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
readOnly={props.readOnly}
ref={props.inputRef}
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-antd/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function Text(props: TextFieldProps) {
<Input
disabled={props.disabled}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
readOnly={props.readOnly}
ref={props.inputRef}
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-bootstrap4/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function LongText(props: LongTextFieldProps) {
disabled={props.disabled}
id={props.id}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
readOnly={props.readOnly}
ref={props.inputRef}
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-bootstrap4/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function Text(props: TextFieldProps) {
disabled={props.disabled}
id={props.id}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
readOnly={props.readOnly}
ref={props.inputRef}
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-bootstrap5/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ function LongText(props: LongTextFieldProps) {
disabled={props.disabled}
id={props.id}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
minLength={props.minLength}
maxLength={props.maxLength}
Expand Down
6 changes: 5 additions & 1 deletion packages/uniforms-bootstrap5/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function Text(props: TextFieldProps) {
disabled={props.disabled}
id={props.id}
name={props.name}
onChange={event => props.onChange(event.target.value)}
onChange={event =>
props.onChange(
event.target.value === '' ? undefined : event.target.value,
)
}
placeholder={props.placeholder}
minLength={props.minLength}
maxLength={props.maxLength}
Expand Down
5 changes: 4 additions & 1 deletion packages/uniforms-mui/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const LongText = ({
margin="dense"
multiline
name={name}
onChange={event => disabled || onChange(event.target.value)}
onChange={event =>
disabled ||
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
ref={inputRef}
type={type}
Expand Down
5 changes: 4 additions & 1 deletion packages/uniforms-mui/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function Text({
label={label}
margin="dense"
name={name}
onChange={event => disabled || onChange(event.target.value)}
onChange={event =>
disabled ||
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
ref={inputRef}
type={type}
Expand Down
4 changes: 3 additions & 1 deletion packages/uniforms-semantic/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function LongText({
disabled={disabled}
id={id}
name={name}
onChange={event => onChange(event.target.value)}
onChange={event =>
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
readOnly={readOnly}
ref={inputRef}
Expand Down
4 changes: 3 additions & 1 deletion packages/uniforms-semantic/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function Text({
disabled={disabled}
id={id}
name={name}
onChange={event => onChange(event.target.value)}
onChange={event =>
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
readOnly={readOnly}
ref={inputRef}
Expand Down
4 changes: 3 additions & 1 deletion packages/uniforms-unstyled/src/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function LongText({
disabled={disabled}
id={id}
name={name}
onChange={event => onChange(event.target.value)}
onChange={event =>
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
readOnly={readOnly}
ref={inputRef}
Expand Down
4 changes: 3 additions & 1 deletion packages/uniforms-unstyled/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function Text({
disabled={disabled}
id={id}
name={name}
onChange={event => onChange(event.target.value)}
onChange={event =>
onChange(event.target.value === '' ? undefined : event.target.value)
}
placeholder={placeholder}
readOnly={readOnly}
ref={inputRef}
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms/__suites__/LongTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function testLongTextField(
schema: z.object({ x: z.string() }),
});
await userEvent.type(screen.getByRole('textbox'), '{Backspace}');
expect(onChange).toHaveBeenLastCalledWith('x', '');
expect(onChange).toHaveBeenLastCalledWith('x', undefined);
});

test('<LongTextField> - renders a label', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms/__suites__/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function testTextField(
schema: z.object({ x: z.string() }),
});
await userEvent.type(screen.getByRole('textbox'), '{Backspace}');
expect(onChange).toHaveBeenLastCalledWith('x', '');
expect(onChange).toHaveBeenLastCalledWith('x', undefined);
});

test('<TextField> - renders a label', () => {
Expand Down

0 comments on commit 6fe2b41

Please sign in to comment.