Skip to content

Commit a4ff972

Browse files
adammationsdirix
authored andcommitted
feat: React Vanilla text cell password support
The UI Schema option "format: 'password'" can be used to render a React Vanilla text cell of type password.
1 parent 01b08f0 commit a4ff972

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/vanilla-renderers/src/cells/TextCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const TextCell = (props: CellProps & VanillaRendererProps) => {
5050
const appliedUiSchemaOptions = merge({}, config, uischema.options);
5151
return (
5252
<input
53-
type='text'
53+
type={appliedUiSchemaOptions.format === 'password' ? 'password' : 'text'}
5454
value={data || ''}
5555
onChange={(ev) =>
5656
handleChange(path, ev.target.value === '' ? undefined : ev.target.value)

packages/vanilla-renderers/test/renderers/TextCell.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,37 @@ describe('Text cell', () => {
593593
expect(input.maxLength).toBe(defaultMaxLength);
594594
expect(input.size).toBe(defaultSize);
595595
});
596+
597+
test('default type is text', () => {
598+
const uischema: ControlElement = {
599+
type: 'Control',
600+
scope: '#/properties/name',
601+
};
602+
const core = initCore(fixture.schema, uischema, fixture.data);
603+
wrapper = mount(
604+
<JsonFormsStateProvider initState={{ core }}>
605+
<TextCell schema={fixture.schema} uischema={uischema} path='name' />
606+
</JsonFormsStateProvider>
607+
);
608+
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
609+
expect(input.type).toBe('text');
610+
});
611+
612+
test('change type to password', () => {
613+
const uischema: ControlElement = {
614+
type: 'Control',
615+
scope: '#/properties/name',
616+
options: {
617+
format: 'password',
618+
},
619+
};
620+
const core = initCore(fixture.schema, uischema, fixture.data);
621+
wrapper = mount(
622+
<JsonFormsStateProvider initState={{ core }}>
623+
<TextCell schema={fixture.schema} uischema={uischema} path='name' />
624+
</JsonFormsStateProvider>
625+
);
626+
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
627+
expect(input.type).toBe('password');
628+
});
596629
});

0 commit comments

Comments
 (0)