Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSH-10063-Add-percentage-as-unit-in-for-text-property-fields #190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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