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

Allow to pass as UISchema options placeholder attribute for TextCell and TextAreaCell cells #1844

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
8 changes: 4 additions & 4 deletions packages/examples/src/day2.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
The MIT License

Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
16 changes: 9 additions & 7 deletions packages/vanilla/src/cells/TextAreaCell.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
The MIT License

Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -32,18 +32,20 @@ import {
import { withJsonFormsCellProps } from '@jsonforms/react';
import { VanillaRendererProps } from '../index';
import { withVanillaCellProps } from '../util/index';
import merge from 'lodash/merge';

export const TextAreaCell = (props: CellProps & VanillaRendererProps) => {
const { data, className, id, enabled, uischema, path, handleChange } = props;

const { data, className, id, enabled, config, uischema, path, handleChange } = props;
const appliedUiSchemaOptions = merge({}, config, uischema.options);
return (
<textarea
value={data || ''}
onChange={ev => handleChange(path, ev.target.value)}
className={className}
id={id}
disabled={!enabled}
autoFocus={uischema.options && uischema.options.focus}
autoFocus={appliedUiSchemaOptions.focus}
placeholder={appliedUiSchemaOptions.placeholder}
/>
);
};
Expand Down
9 changes: 5 additions & 4 deletions packages/vanilla/src/cells/TextCell.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
The MIT License

Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -57,6 +57,7 @@ export const TextCell = (props: CellProps & VanillaRendererProps) => {
id={id}
disabled={!enabled}
autoFocus={appliedUiSchemaOptions.focus}
placeholder={appliedUiSchemaOptions.placeholder}
maxLength={appliedUiSchemaOptions.restrict ? maxLength : undefined}
size={appliedUiSchemaOptions.trim ? maxLength : undefined}
/>
Expand Down
18 changes: 18 additions & 0 deletions packages/vanilla/test/renderers/TextAreaCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ describe('Text area cell', () => {
const textArea = wrapper.find('textarea').getDOMNode() as HTMLTextAreaElement;
expect(textArea.disabled).toBe(false);
});

test('accept placeholder attribute', () => {
const uischema: ControlElement = {
type: 'Control',
scope: '#/properties/name',
options: {
placeholder: 'Placeholder for name field'
}
};
const core = initCore(fixture.schema, uischema, fixture.data);
wrapper = mount(
<JsonFormsStateProvider initState={{ core }}>
<TextAreaCell schema={fixture.schema} uischema={uischema} path='name' />
</JsonFormsStateProvider>
);
const textArea = wrapper.find('textarea').getDOMNode() as HTMLTextAreaElement;
expect(textArea.placeholder).toBe('Placeholder for name field');
});
});

describe('Text area cell tester', () => {
Expand Down
18 changes: 18 additions & 0 deletions packages/vanilla/test/renderers/TextCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,24 @@ describe('Text cell', () => {
expect(input.disabled).toBe(false);
});

test('accept placeholder attribute', () => {
const uischema: ControlElement = {
type: 'Control',
scope: '#/properties/name',
options: {
placeholder: 'Placeholder for name field'
}
};
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.placeholder).toBe('Placeholder for name field');
});

test('use maxLength for attributes size and maxlength', () => {
const uischema: ControlElement = {
type: 'Control',
Expand Down