Skip to content

Commit d5a9038

Browse files
authored
Placeholder support for React Vanilla text cells
Allows to configure a 'placeholder' for React Vanilla text cells via the UI Schema options, similar to Vue Vanilla.
1 parent 93f1373 commit d5a9038

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

packages/examples/src/day2.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2017-2019 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

packages/vanilla/src/cells/TextAreaCell.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2017-2019 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -32,18 +32,20 @@ import {
3232
import { withJsonFormsCellProps } from '@jsonforms/react';
3333
import { VanillaRendererProps } from '../index';
3434
import { withVanillaCellProps } from '../util/index';
35+
import merge from 'lodash/merge';
3536

3637
export const TextAreaCell = (props: CellProps & VanillaRendererProps) => {
37-
const { data, className, id, enabled, uischema, path, handleChange } = props;
38-
38+
const { data, className, id, enabled, config, uischema, path, handleChange } = props;
39+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
3940
return (
4041
<textarea
4142
value={data || ''}
4243
onChange={ev => handleChange(path, ev.target.value)}
4344
className={className}
4445
id={id}
4546
disabled={!enabled}
46-
autoFocus={uischema.options && uischema.options.focus}
47+
autoFocus={appliedUiSchemaOptions.focus}
48+
placeholder={appliedUiSchemaOptions.placeholder}
4749
/>
4850
);
4951
};

packages/vanilla/src/cells/TextCell.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2017-2019 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -57,6 +57,7 @@ export const TextCell = (props: CellProps & VanillaRendererProps) => {
5757
id={id}
5858
disabled={!enabled}
5959
autoFocus={appliedUiSchemaOptions.focus}
60+
placeholder={appliedUiSchemaOptions.placeholder}
6061
maxLength={appliedUiSchemaOptions.restrict ? maxLength : undefined}
6162
size={appliedUiSchemaOptions.trim ? maxLength : undefined}
6263
/>

packages/vanilla/test/renderers/TextAreaCell.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,24 @@ describe('Text area cell', () => {
313313
const textArea = wrapper.find('textarea').getDOMNode() as HTMLTextAreaElement;
314314
expect(textArea.disabled).toBe(false);
315315
});
316+
317+
test('accept placeholder attribute', () => {
318+
const uischema: ControlElement = {
319+
type: 'Control',
320+
scope: '#/properties/name',
321+
options: {
322+
placeholder: 'Placeholder for name field'
323+
}
324+
};
325+
const core = initCore(fixture.schema, uischema, fixture.data);
326+
wrapper = mount(
327+
<JsonFormsStateProvider initState={{ core }}>
328+
<TextAreaCell schema={fixture.schema} uischema={uischema} path='name' />
329+
</JsonFormsStateProvider>
330+
);
331+
const textArea = wrapper.find('textarea').getDOMNode() as HTMLTextAreaElement;
332+
expect(textArea.placeholder).toBe('Placeholder for name field');
333+
});
316334
});
317335

318336
describe('Text area cell tester', () => {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,24 @@ describe('Text cell', () => {
319319
expect(input.disabled).toBe(false);
320320
});
321321

322+
test('accept placeholder attribute', () => {
323+
const uischema: ControlElement = {
324+
type: 'Control',
325+
scope: '#/properties/name',
326+
options: {
327+
placeholder: 'Placeholder for name field'
328+
}
329+
};
330+
const core = initCore(fixture.schema, uischema, fixture.data);
331+
wrapper = mount(
332+
<JsonFormsStateProvider initState={{ core }}>
333+
<TextCell schema={fixture.schema} uischema={uischema} path='name' />
334+
</JsonFormsStateProvider>
335+
);
336+
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
337+
expect(input.placeholder).toBe('Placeholder for name field');
338+
});
339+
322340
test('use maxLength for attributes size and maxlength', () => {
323341
const uischema: ControlElement = {
324342
type: 'Control',

0 commit comments

Comments
 (0)