diff --git a/__tests__/SelectField.tsx b/__tests__/SelectField.tsx index 7a59956..79e2aab 100644 --- a/__tests__/SelectField.tsx +++ b/__tests__/SelectField.tsx @@ -252,6 +252,20 @@ test(' - renders a label', () => { ); }); +test(' - renders a number label', () => { + const element = ; + 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(' - renders a wrapper with unknown props', () => { const element = ; const wrapper = mount( diff --git a/examples/App.js b/examples/App.js index 4155c52..f4da287 100644 --- a/examples/App.js +++ b/examples/App.js @@ -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'; diff --git a/examples/package.json b/examples/package.json index 57186ad..f7118e2 100644 --- a/examples/package.json +++ b/examples/package.json @@ -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", diff --git a/examples/schema/json-schema.js b/examples/schema/json-schema.js index f91160d..01f87fe 100644 --- a/examples/schema/json-schema.js +++ b/examples/schema/json-schema.js @@ -59,6 +59,11 @@ const schema = { }, room: { type: 'string' + }, + numberOfBeds: { + placeholder: "Select...", + enum: [1, 2, 3], + type: 'number' } }, } diff --git a/src/SelectField.tsx b/src/SelectField.tsx index ec3a14d..02f5b85 100644 --- a/src/SelectField.tsx +++ b/src/SelectField.tsx @@ -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;