Skip to content

Commit 988f282

Browse files
authored
Rule support for React Vanilla layouts
- Pass enabled prop to individual group elements (React Vanilla) - Implement enabled prop for Radiogroup (React Vanilla & Material) Closes #1586
1 parent 7532a3e commit 988f282

File tree

8 files changed

+29
-6
lines changed

8 files changed

+29
-6
lines changed

packages/material/src/controls/MaterialRadioGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export const MaterialRadioGroup = (props: ControlProps & OwnPropsOfEnum) => {
5454
visible,
5555
options,
5656
handleChange,
57-
path
57+
path,
58+
enabled
5859
} = props;
5960
const isValid = errors.length === 0;
6061
const appliedUiSchemaOptions = merge(
@@ -99,6 +100,7 @@ export const MaterialRadioGroup = (props: ControlProps & OwnPropsOfEnum) => {
99100
key={option.label}
100101
control={<Radio checked={data === option.value} />}
101102
label={option.label}
103+
disabled={!enabled}
102104
/>
103105
))}
104106
</RadioGroup>

packages/vanilla/src/controls/InputControl.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class InputControl extends Control<
5757
uischema,
5858
schema,
5959
visible,
60+
enabled,
6061
required,
6162
path,
6263
cells,
@@ -104,6 +105,7 @@ export class InputControl extends Control<
104105
schema={schema}
105106
path={path}
106107
id={id + '-input'}
108+
enabled={enabled}
107109
/>
108110
<div className={divClassNames}>
109111
{!isValid ? errors : showDescription ? description : null}

packages/vanilla/src/controls/RadioGroup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export class RadioGroup extends Control<
5050
data,
5151
uischema,
5252
visible,
53-
config
53+
config,
54+
enabled
5455
} = this.props;
5556
const isValid = errors.length === 0;
5657
const divClassNames = `validation ${isValid ? classNames.description : 'validation_error'
@@ -93,6 +94,7 @@ export class RadioGroup extends Control<
9394
name={id}
9495
checked={data === option.value}
9596
onChange={ev => this.handleChange(ev.currentTarget.value)}
97+
disabled={!enabled}
9698
/>
9799
<label htmlFor={option.value}>{option.label}</label>
98100
</div>

packages/vanilla/src/layouts/GroupLayout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const GroupLayoutRendererComponent: FunctionComponent<RendererProps & VanillaRen
4848
schema,
4949
uischema,
5050
path,
51+
enabled,
5152
visible,
5253
getStyle,
5354
getStyleAsClassName
@@ -70,7 +71,7 @@ const GroupLayoutRendererComponent: FunctionComponent<RendererProps & VanillaRen
7071
{group.label}
7172
</legend> : ''
7273
}
73-
{renderChildren(group, schema, childClassNames, path)}
74+
{renderChildren(group, schema, childClassNames, path, enabled)}
7475
</fieldset>
7576
);
7677
});

packages/vanilla/src/layouts/HorizontalLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const HorizontalLayoutRendererComponent: FunctionComponent<RendererProps & Vanil
7878
getStyle={getStyle}
7979
getStyleAsClassName={getStyleAsClassName}
8080
>
81-
{renderChildren(horizontalLayout, schema, childClassNames, path)}
81+
{renderChildren(horizontalLayout, schema, childClassNames, path, enabled)}
8282
</JsonFormsLayout>
8383
);
8484
});

packages/vanilla/src/layouts/VerticalLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const VerticalLayoutRendererComponent: FunctionComponent<RendererProps & Vanilla
7777
getStyle={getStyle}
7878
getStyleAsClassName={getStyleAsClassName}
7979
>
80-
{renderChildren(verticalLayout, schema, childClassNames, path)}
80+
{renderChildren(verticalLayout, schema, childClassNames, path, enabled)}
8181
</JsonFormsLayout>
8282
);
8383
});

packages/vanilla/src/layouts/util.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const renderChildren = (
3737
layout: Layout,
3838
schema: JsonSchema,
3939
className: string,
40-
path: string
40+
path: string,
41+
enabled: boolean
4142
) => {
4243
if (isEmpty(layout.elements)) {
4344
return [];
@@ -54,6 +55,7 @@ export const renderChildren = (
5455
uischema={child}
5556
schema={schema}
5657
path={path}
58+
enabled={enabled}
5759
/>
5860
</div>
5961
);

packages/vanilla/test/renderers/GroupLayout.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ describe('Group layout', () => {
123123
expect(groupLayout.props().hidden).toBe(true);
124124
});
125125

126+
test('pass enabled prop to children', () => {
127+
const core = initCore({}, fixture.uischema, {});
128+
wrapper = mount(
129+
<JsonFormsStateProvider initState={{ core }}>
130+
<GroupLayoutRenderer
131+
uischema={fixture.uischema}
132+
enabled={false}
133+
/>
134+
</JsonFormsStateProvider>
135+
);
136+
const child = wrapper.find('JsonFormsDispatchRenderer');
137+
expect(child.prop('enabled')).toBe(false);
138+
});
139+
126140
test('show by default', () => {
127141
const core = initCore({}, fixture.uischema, {});
128142
wrapper = mount(

0 commit comments

Comments
 (0)