Skip to content

Commit afb4d83

Browse files
authored
Merge pull request #1149 from steverhoades/remove-delete-all-when-minItems-set
fix(pf4): Field-Array no longer shows delete all when minItems has a …
2 parents 897adb1 + 8107659 commit afb4d83

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

packages/pf4-component-mapper/src/field-array/field-array.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ const DynamicArray = ({ ...props }) => {
9595
titleDescription={description}
9696
actions={
9797
<React.Fragment>
98-
<Button
99-
variant="link"
100-
isDisabled={value.length === 0}
101-
{...(value.length !== 0 && { onClick: () => removeBatch(value.map((_, index) => index)) })}
102-
>
103-
{combinedButtonLabels.removeAll}
104-
</Button>
98+
{minItems === 0 && (
99+
<Button
100+
variant="link"
101+
isDisabled={value.length === 0}
102+
{...(value.length !== 0 && { onClick: () => removeBatch(value.map((_, index) => index)) })}
103+
>
104+
{combinedButtonLabels.removeAll}
105+
</Button>
106+
)}
105107
<Button
106108
variant="secondary"
107109
isDisabled={value.length >= maxItems}

packages/pf4-component-mapper/src/tests/field-array.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('<FieldArray/>', () => {
306306
});
307307

308308
await act(async () => {
309-
wrapper.find('button').at(1).simulate('click');
309+
wrapper.find('button').at(0).simulate('click');
310310
});
311311
wrapper.update();
312312

@@ -321,7 +321,7 @@ describe('<FieldArray/>', () => {
321321
onSubmit.mockClear();
322322

323323
await act(async () => {
324-
wrapper.find('button').at(1).simulate('click');
324+
wrapper.find('button').at(0).simulate('click');
325325
});
326326
wrapper.update();
327327

@@ -336,7 +336,7 @@ describe('<FieldArray/>', () => {
336336
onSubmit.mockClear();
337337

338338
await act(async () => {
339-
wrapper.find('button').at(1).simulate('click');
339+
wrapper.find('button').at(0).simulate('click');
340340
});
341341
wrapper.update();
342342

0 commit comments

Comments
 (0)