Skip to content

Commit

Permalink
fix: allow enabling empty disabled array states
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWolfZ committed May 30, 2019
1 parent ca93697 commit 8a33d12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/array/reducer/enable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EnableAction } from '../../actions';
import { createFormArrayState } from '../../state';
import { enableReducer } from './enable';
import {
FORM_CONTROL_ID,
Expand Down Expand Up @@ -49,4 +50,15 @@ describe(`form array ${enableReducer.name}`, () => {
const resultState = enableReducer(state, new EnableAction(state.controls[0].id));
expect(resultState).not.toBe(state);
});

it('should enable an empty disabled state', () => {
const state = {
...createFormArrayState<string>(FORM_CONTROL_ID, []),
isDisabled: true,
isEnabled: false,
};

const resultState = enableReducer(state, new EnableAction(FORM_CONTROL_ID));
expect(resultState.isEnabled).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/array/reducer/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function enableReducer<TValue>(

const controls = dispatchActionPerChild(state.controls, controlId => new EnableAction(controlId));

if (controls === state.controls) {
if (controls === state.controls && state.isEnabled) {
return state;
}

Expand Down

0 comments on commit 8a33d12

Please sign in to comment.