Skip to content

Vanilla TextCell password #2249

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

Closed
wants to merge 8 commits into from
Closed
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
4 changes: 3 additions & 1 deletion packages/vanilla-renderers/src/cells/TextCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export const TextCell = (props: CellProps & VanillaRendererProps) => {
const appliedUiSchemaOptions = merge({}, config, uischema.options);
return (
<input
type='text'
type={
appliedUiSchemaOptions.format ? appliedUiSchemaOptions.format : 'text'
}
Comment on lines +53 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type={
appliedUiSchemaOptions.format ? appliedUiSchemaOptions.format : 'text'
}
type={appliedUiSchemaOptions.format === 'password' ? 'password' : 'text'}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer only passing through the password as in React Material. Other types might be incompatible. I would have applied the change myself but maintainer editing was turned off for this PR

value={data || ''}
onChange={(ev) =>
handleChange(path, ev.target.value === '' ? undefined : ev.target.value)
Expand Down
33 changes: 33 additions & 0 deletions packages/vanilla-renderers/test/renderers/TextCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,37 @@ describe('Text cell', () => {
expect(input.maxLength).toBe(defaultMaxLength);
expect(input.size).toBe(defaultSize);
});

test('default type is text', () => {
const uischema: ControlElement = {
type: 'Control',
scope: '#/properties/name',
};
const core = initCore(fixture.schema, uischema, fixture.data);
wrapper = mount(
<JsonFormsStateProvider initState={{ core }}>
<TextCell schema={fixture.schema} uischema={uischema} path='name' />
</JsonFormsStateProvider>
);
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.type).toBe('text');
});

test('change type to password', () => {
const uischema: ControlElement = {
type: 'Control',
scope: '#/properties/name',
options: {
format: 'password',
},
};
const core = initCore(fixture.schema, uischema, fixture.data);
wrapper = mount(
<JsonFormsStateProvider initState={{ core }}>
<TextCell schema={fixture.schema} uischema={uischema} path='name' />
</JsonFormsStateProvider>
);
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.type).toBe('password');
});
});