diff --git a/lib/components-schema-v1_11_x.ts b/lib/components-schema-v1_11_x.ts index ddb6cc9..067fafc 100644 --- a/lib/components-schema-v1_11_x.ts +++ b/lib/components-schema-v1_11_x.ts @@ -232,7 +232,7 @@ const componentPropertyDefinition: { }, unit: { type: 'string', - description: 'Unit type like em, px etc', + description: 'Unit type like em, px, % etc', }, inputPlaceholder: labelProperty('Input placeholder'), readonly: { diff --git a/lib/validators/unit-type-validator.ts b/lib/validators/unit-type-validator.ts index d7f3d87..989c49a 100644 --- a/lib/validators/unit-type-validator.ts +++ b/lib/validators/unit-type-validator.ts @@ -5,7 +5,7 @@ import { Validator } from './validator'; import { Component, ComponentProperty } from '../models'; -const TYPES = ['em', 'px']; +const TYPES = ['em', 'px', '%']; const TYPES_REGEXP = new RegExp(`^(${TYPES.join('|')})$`, 'i'); export class UnitTypeValidator extends Validator { diff --git a/test/validators/unit-type-validator.test.ts b/test/validators/unit-type-validator.test.ts index 0531a38..7de3540 100644 --- a/test/validators/unit-type-validator.test.ts +++ b/test/validators/unit-type-validator.test.ts @@ -30,6 +30,13 @@ describe('UnitTypeValidator', () => { unit: 'eM', // test if it is case-insensitive }, }, + { + name: 'p4', + control: { + type: 'text', + unit: '%', + }, + }, ], }, }, @@ -46,7 +53,7 @@ describe('UnitTypeValidator', () => { definition.components.c1.properties[1].control.unit = 'xy'; validator.validate(); expect(error).toHaveBeenCalledWith( - `Property "p2" has unacceptable unit type "xy", only "em,px" are allowed`, + `Property "p2" has unacceptable unit type "xy", only "em,px,%" are allowed`, ); }); });