Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Fix: A SelectField made of numbers don't pass on validation (#116)
Browse files Browse the repository at this point in the history
* Fix number SelectField

* Fix example
  • Loading branch information
ljmotta authored Dec 22, 2022
1 parent bb4624b commit 95f78e4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions __tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ test('<SelectField> - renders a label', () => {
);
});

test('<SelectField> - renders a number label', () => {
const element = <SelectField required={true} name="x" label={1} />;
const wrapper = mount(
element,
createContext({ x: { type: Number, allowedValues: [1, 2] } }),
);

expect(wrapper.find('label')).toHaveLength(1);
expect(wrapper.find('label').text()).toBe('1 *');
expect(wrapper.find('label').prop('htmlFor')).toBe(
wrapper.find(Select).prop('id'),
);
});

test('<SelectField> - renders a wrapper with unknown props', () => {
const element = <SelectField name="x" data-x="x" data-y="y" data-z="z" />;
const wrapper = mount(
Expand Down
2 changes: 1 addition & 1 deletion examples/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { AutoForm } from 'uniforms-patternfly';
import { AutoForm } from 'uniforms-patternfly/dist/es6';

import { CodeBlock } from './CodeBlock';
import schema from './schema/json-schema';
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"uniforms-bridge-json-schema": "3.5.1",
"uniforms-bridge-simple-schema": "3.5.1",
"uniforms-bridge-simple-schema-2": "3.5.1",
"uniforms-patternfly": "4.7.5"
"uniforms-patternfly": "4.7.7"
},
"devDependencies": {
"parcel-bundler": "^1.12.5",
Expand Down
5 changes: 5 additions & 0 deletions examples/schema/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const schema = {
},
room: {
type: 'string'
},
numberOfBeds: {
placeholder: "Select...",
enum: [1, 2, 3],
type: 'number'
}
},
}
Expand Down
4 changes: 3 additions & 1 deletion src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ type SelectInputProps = FieldProps<
function isSelectOptionObject(
toBeDetermined: string | SelectOptionObject
): toBeDetermined is SelectOptionObject {
return toBeDetermined.toString !== undefined;
return typeof toBeDetermined === 'object' &&
!Array.isArray(toBeDetermined) &&
toBeDetermined !== null
}

export type SelectFieldProps = CheckboxesProps | SelectInputProps;
Expand Down

0 comments on commit 95f78e4

Please sign in to comment.