Skip to content

Commit

Permalink
Moved schema component to defaultComponentDetector (closes #1114).
Browse files Browse the repository at this point in the history
  • Loading branch information
wadamek65 authored Oct 18, 2022
1 parent 7cb762a commit 15cf843
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/migrating-3-to-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ This guide is designed to help you through the migration. If you went through it

## Breaking API changes

- `componentDetector` in `AutoField`s now always takes precedence over `component` property on a schema. This may make your `AutoField` render a different component when you were using both previously. If that's the case, move your schema's `component` definition to a [`AutoField.componentDetectorContext.Provider`](/docs/uth-autofield-algorithm/#overriding-autofield) instead.
- Dropped support for `initialCount` in bridges and `ListField`s. Pass a model object to the form with the appropriate amount of initial items instead.
- `AutoFields` component in all themes now renders a `React.Fragment` instead of a `div`. Explicitly render a wrapper component around if you need one.
4 changes: 4 additions & 0 deletions packages/uniforms-antd/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-bootstrap3/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-bootstrap4/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-bootstrap5/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-material/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-mui/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-semantic/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
4 changes: 4 additions & 0 deletions packages/uniforms-unstyled/src/AutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import SelectField from './SelectField';
import TextField from './TextField';

const AutoField = createAutoField(props => {
if (props.component) {
return props.component;
}

if (props.allowedValues) {
return props.checkboxes && props.fieldType !== Array
? RadioField
Expand Down
2 changes: 1 addition & 1 deletion packages/uniforms/src/createAutoField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function createAutoField(defaultComponentDetector: ComponentDetector) {
function AutoField(rawProps: AutoFieldProps): ReactElement {
const [props, uniforms] = useField(rawProps.name, rawProps);
const componentDetector = useContext(context);
const component = props.component ?? componentDetector(props, uniforms);
const component = componentDetector(props, uniforms);

invariant(component, 'AutoField received no component for: %s', props.name);

Expand Down

0 comments on commit 15cf843

Please sign in to comment.