Skip to content

Commit

Permalink
Merge pull request #190 from WoodWing/CSH-10063-Add-percentage-as-uni…
Browse files Browse the repository at this point in the history
…t-in-for-text-property-fields

CSH-10063-Add-percentage-as-unit-in-for-text-property-fields
  • Loading branch information
Gecete authored Dec 18, 2023
2 parents 1ae9c4b + 0eab237 commit c91968e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/components-schema-v1_11_x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion lib/validators/unit-type-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion test/validators/unit-type-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ describe('UnitTypeValidator', () => {
unit: 'eM', // test if it is case-insensitive
},
},
{
name: 'p4',
control: {
type: 'text',
unit: '%',
},
},
],
},
},
Expand All @@ -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`,
);
});
});
Expand Down

0 comments on commit c91968e

Please sign in to comment.