Skip to content

Commit c8f1a46

Browse files
committed
optimize hideTitle WidgetCode; fix showValidity WidgetCode/Selectable;
1 parent 06b360d commit c8f1a46

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

packages/material-code/src/WidgetCode/WidgetCode.tsx

+19-14
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,27 @@ export const WidgetCode: React.ComponentType<WidgetProps & WithScalarValue & Wid
5555
const hideTitle = schema?.getIn(['view', 'hideTitle'])
5656
const readOnly = readOnlyProp || schema?.get('readOnly')
5757

58-
const classNamesContent = React.useMemo(() => (valid ? undefined : ['invalid']), [valid])
58+
const classNamesContent = React.useMemo(
59+
() => (!showValidity || valid ? undefined : ['invalid']),
60+
[valid, showValidity],
61+
)
5962
const CodeBarComp = CustomCodeBar || CodeBar
63+
const showTitle = required || formatValue || !hideTitle
6064
return <>
61-
<Box mb={0.5}>
62-
<FormLabel error={(!valid && showValidity)}>
63-
{hideTitle ? null : <>
64-
<TransTitle storeKeys={storeKeys} schema={schema}/>
65-
{required ? ' *' : null}
66-
</>}
67-
{formatValue ? <>
68-
{hideTitle ? null : ' ('}
69-
<Trans text={'formats.' + formatValue} fallback={formatValue}/>
70-
{hideTitle ? null : ')'}
71-
</> : null}
72-
</FormLabel>
73-
</Box>
65+
{showTitle ?
66+
<Box mb={0.5}>
67+
<FormLabel error={(!valid && showValidity)}>
68+
{hideTitle ? null : <>
69+
<TransTitle storeKeys={storeKeys} schema={schema}/>
70+
{required ? ' *' : null}
71+
</>}
72+
{formatValue ? <>
73+
{hideTitle ? null : ' ('}
74+
<Trans text={'formats.' + formatValue} fallback={formatValue}/>
75+
{hideTitle ? null : ')'}
76+
</> : null}
77+
</FormLabel>
78+
</Box> : null}
7479

7580
<CodeMirror
7681
value={(value as string) || ''}

packages/material-code/src/WidgetCodeSelectable/WidgetCodeSelectable.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export const WidgetCodeSelectable: React.ComponentType<WidgetProps & WithScalarV
6868
const hideTitle = schema?.getIn(['view', 'hideTitle'])
6969
const readOnly = readOnlyProp || schema?.get('readOnly')
7070

71-
const classNamesContent = React.useMemo(() => (valid ? undefined : ['invalid']), [valid])
71+
const classNamesContent = React.useMemo(
72+
() => (!showValidity || valid ? undefined : ['invalid']),
73+
[valid, showValidity],
74+
)
7275
const CodeBarComp = CustomCodeBar || CodeBar
7376
return <>
7477
{hideTitle ? null :
@@ -102,7 +105,7 @@ export const WidgetCodeSelectable: React.ComponentType<WidgetProps & WithScalarV
102105
f =>
103106
<MenuItem key={f} value={f} dense>
104107
<Trans text={'formats.' + f} fallback={f}/>
105-
</MenuItem>
108+
</MenuItem>,
106109
)}
107110
</Select>
108111
}

0 commit comments

Comments
 (0)