Skip to content

fix: ui:emptyValue behavior #2457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 12 additions & 69 deletions packages/antd/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"peerDependencies": {
"@ant-design/icons": "^4.0.0",
"@rjsf/core": "^2.0.0",
"@rjsf/core": "^3.0.0",
"antd": "^4.0.0",
"antd-dayjs-webpack-plugin": "1.0.0",
"dayjs": "^1.8.0",
Expand Down
7 changes: 3 additions & 4 deletions packages/antd/src/widgets/EmailWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

import { utils } from '@rjsf/core';
import Input from 'antd/lib/input';

const INPUT_STYLE = {
Expand All @@ -24,8 +24,7 @@ const EmailWidget = ({
}) => {
const { readonlyAsDisabled = true } = formContext;

const handleChange = ({ target }) =>
onChange(target.value === '' ? options.emptyValue : target.value);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = ({ target }) => onBlur(id, target.value);

Expand All @@ -37,7 +36,7 @@ const EmailWidget = ({
id={id}
name={id}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
style={INPUT_STYLE}
Expand Down
9 changes: 3 additions & 6 deletions packages/antd/src/widgets/PasswordWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

import {utils} from '@rjsf/core';
import Input from 'antd/lib/input';

const PasswordWidget = ({
Expand All @@ -20,10 +20,7 @@ const PasswordWidget = ({
}) => {
const { readonlyAsDisabled = true } = formContext;

const emptyValue = options.emptyValue || '';

const handleChange = ({ target }) =>
onChange(target.value === '' ? emptyValue : target.value);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = ({ target }) => onBlur(id, target.value);

Expand All @@ -35,7 +32,7 @@ const PasswordWidget = ({
id={id}
name={id}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
value={value || ''}
Expand Down
10 changes: 3 additions & 7 deletions packages/antd/src/widgets/RangeWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable no-else-return */
import React from 'react';

import { utils } from '@rjsf/core';
import Slider from 'antd/lib/slider';
import { utils } from '@rjsf/core';

const { rangeSpec } = utils;

Expand All @@ -26,10 +25,7 @@ const RangeWidget = ({

const { min, max, step } = rangeSpec(schema);

const emptyValue = options.emptyValue || '';

const handleChange = (nextValue) =>
onChange(nextValue === '' ? emptyValue : nextValue);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = () => onBlur(id, value);

Expand All @@ -43,7 +39,7 @@ const RangeWidget = ({
max={max}
min={min}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
range={false}
Expand Down
7 changes: 3 additions & 4 deletions packages/antd/src/widgets/TextWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

import {utils} from '@rjsf/core';
import Input from 'antd/lib/input';
import InputNumber from 'antd/lib/input-number';

Expand Down Expand Up @@ -27,8 +27,7 @@ const TextWidget = ({

const handleNumberChange = (nextValue) => onChange(nextValue);

const handleTextChange = ({ target }) =>
onChange(target.value === '' ? options.emptyValue : target.value);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = ({ target }) => onBlur(id, target.value);

Expand All @@ -53,7 +52,7 @@ const TextWidget = ({
id={id}
name={id}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleTextChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
style={INPUT_STYLE}
Expand Down
7 changes: 3 additions & 4 deletions packages/antd/src/widgets/TextareaWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

import {utils} from '@rjsf/core';
import Input from 'antd/lib/input';

const INPUT_STYLE = {
Expand All @@ -24,8 +24,7 @@ const TextareaWidget = ({
}) => {
const { readonlyAsDisabled = true } = formContext;

const handleChange = ({ target }) =>
onChange(target.value === '' ? options.emptyValue : target.value);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = ({ target }) => onBlur(id, target.value);

Expand All @@ -37,7 +36,7 @@ const TextareaWidget = ({
id={id}
name={id}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
rows={options.rows || 4}
Expand Down
7 changes: 3 additions & 4 deletions packages/antd/src/widgets/URLWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

import {utils} from '@rjsf/core';
import Input from 'antd/lib/input';

const INPUT_STYLE = {
Expand All @@ -24,8 +24,7 @@ const URLWidget = ({
}) => {
const { readonlyAsDisabled = true } = formContext;

const handleChange = ({ target }) =>
onChange(target.value === '' ? options.emptyValue : target.value);
const {onEventChange} = utils.hooks.useEmptyValueOnChange({onChange, options, value});

const handleBlur = ({ target }) => onBlur(id, target.value);

Expand All @@ -37,7 +36,7 @@ const URLWidget = ({
id={id}
name={id}
onBlur={!readonly ? handleBlur : undefined}
onChange={!readonly ? handleChange : undefined}
onChange={!readonly ? onEventChange : undefined}
onFocus={!readonly ? handleFocus : undefined}
placeholder={placeholder}
style={INPUT_STYLE}
Expand Down
Loading