Skip to content

Commit

Permalink
Merge branch 'master' into remove_enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestTeluk committed Jul 26, 2024
2 parents 6f55f05 + e2c77bf commit a935644
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 92 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
7 changes: 6 additions & 1 deletion packages/uniforms-bridge-zod/src/ZodBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export default class ZodBridge<T extends ZodRawShape> extends Bridge {
}

getInitialValue(name: string): unknown {
const field = this.getField(name);
let field = this.getField(name);

if (field instanceof ZodOptional) {
field = field.unwrap();
}

if (field instanceof ZodArray) {
const item = this.getInitialValue(joinName(name, '$'));
if (item === undefined) {
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
13 changes: 11 additions & 2 deletions website/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import styles from '../lib/styles';
import { themes } from '../lib/universal';
import { compress, parseQuery, updateQuery } from '../lib/utils';

function replacer(key: string, value: any) {
return value === undefined ? 'undefined' : value;
}

export class Playground extends Component<any, any> {
static getDerivedStateFromError(error: Error) {
return { error };
Expand Down Expand Up @@ -116,7 +120,12 @@ const PlaygroundModelDebug = () => {
<br />
<br />
<pre>
<code>{`const model = ${JSON.stringify(model, null, 2)};`}</code>
<code>
{`const model = ${JSON.stringify(model, replacer, 2)};`.replace(
/"undefined"/g,
'undefined',
)}
</code>
</pre>
</>
);
Expand Down Expand Up @@ -198,7 +207,7 @@ class PlaygroundProps extends Component<any, any> {
<PlaygroundWrap theme={theme}>
<AutoForm
autosave
autosaveDelay={100}
autosaveDelay={1000}
model={value}
onSubmit={onChange}
schema={schema}
Expand Down
Loading

0 comments on commit a935644

Please sign in to comment.