diff --git a/packages/core/src/util/renderer.ts b/packages/core/src/util/renderer.ts index 8589f70ea..dc2a7f969 100644 --- a/packages/core/src/util/renderer.ts +++ b/packages/core/src/util/renderer.ts @@ -88,6 +88,7 @@ const isRequired = ( * * @param {string} label the label string * @param {boolean} required whether the label belongs to a control which is required + * @param {boolean} hideRequiredAsterisk applied UI Schema option * @returns {string} the label string */ export const computeLabel = ( @@ -98,6 +99,20 @@ export const computeLabel = ( return required && !hideRequiredAsterisk ? label + '*' : label; }; +/** + * Indicates whether to mark a field as required. + * + * @param {boolean} required whether the label belongs to a control which is required + * @param {boolean} hideRequiredAsterisk applied UI Schema option + * @returns {boolean} should the field be marked as required + */ + export const showAsRequired = ( + required: boolean, + hideRequiredAsterisk: boolean +): boolean => { + return required && !hideRequiredAsterisk; +}; + /** * Create a default value based on the given scheam. * @param schema the schema for which to create a default value. diff --git a/packages/material/src/controls/MaterialInputControl.tsx b/packages/material/src/controls/MaterialInputControl.tsx index 59061dd66..1b3a1cb74 100644 --- a/packages/material/src/controls/MaterialInputControl.tsx +++ b/packages/material/src/controls/MaterialInputControl.tsx @@ -24,7 +24,7 @@ */ import React from 'react'; import { - computeLabel, + showAsRequired, ControlProps, ControlState, isDescriptionHidden, @@ -84,12 +84,10 @@ export abstract class MaterialInputControl extends Control< - {computeLabel( - label, - required, - appliedUiSchemaOptions.hideRequiredAsterisk - )} + {label} { return ( - {computeLabel( - label, - required, - appliedUiSchemaOptions.hideRequiredAsterisk - )} + {label} { onBlur={this.onBlur} id={id} > - - {computeLabel( - label, - required, - appliedUiSchemaOptions.hideRequiredAsterisk - )} - + + + {label} + +
{schema.minimum} diff --git a/packages/material/test/renderers/MaterialInputControl.test.tsx b/packages/material/test/renderers/MaterialInputControl.test.tsx index a5c0a3e8e..1e383e1c9 100644 --- a/packages/material/test/renderers/MaterialInputControl.test.tsx +++ b/packages/material/test/renderers/MaterialInputControl.test.tsx @@ -283,7 +283,7 @@ describe('Material input control', () => { ); const label = wrapper.find('label').first(); - expect(label.text()).toBe('Date Cell*'); + expect(label.text()).toBe('Date Cell *'); }); it('should not display a marker for a non-required prop', () => {