Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

Commit 9d7d59f

Browse files
committed
Add custom label for add button on array of items
1 parent 1e3ad8d commit 9d7d59f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"ui:options": {
3+
"addButtonLabel": "Custom add label"
4+
}
5+
}

src/AddButton/AddButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { AddButtonProps } from 'react-jsonschema-form';
55
import Button from '@material-ui/core/Button';
66
import AddIcon from '@material-ui/icons/Add';
77

8-
const AddButton: React.FC<AddButtonProps> = props => (
8+
// TODO: Add label property on type definition
9+
const AddButton: React.FC<AddButtonProps & { label?: string }> = props => (
910
<Button {...props} color="secondary">
1011
<AddIcon /> {props.label || 'Add Item'}
1112
</Button>

src/ArrayFieldTemplate/ArrayFieldTemplate.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ const DefaultNormalArrayFieldTemplate = (props: ArrayFieldTemplateProps) => {
193193
className="array-item-add"
194194
onClick={props.onAddClick}
195195
disabled={props.disabled || props.readonly}
196-
label={props.uiSchema.buttonLabel}
196+
{...(props.uiSchema['ui:options'] && {
197+
label: props.uiSchema['ui:options'][
198+
'addButtonLabel'
199+
] as string,
200+
})}
197201
/>
198202
</Box>
199203
</Grid>

0 commit comments

Comments
 (0)