Skip to content

Commit d652ffd

Browse files
committed
fix: Addressed CC comment
resolves #1109
1 parent 7c8c635 commit d652ffd

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

packages/components/src/BasicModal.test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ it('focuses default button on first render after opening', () => {
3131
expect(getByTestId(`${DEFAULT_TEST_ID}-btn-confirm`)).toHaveFocus();
3232
});
3333

34-
it('focuses cancel button on first render if isConfirmDanger is true', () => {
35-
const { getByTestId } = makeWrapper({ isConfirmDanger: true });
36-
expect(getByTestId(`${DEFAULT_TEST_ID}-btn-cancel`)).toHaveFocus();
37-
});
34+
it.each([true, false])(
35+
'sets button style based on isConfirmDanger value: %s',
36+
isConfirmDanger => {
37+
const { getByTestId } = makeWrapper({ isConfirmDanger });
38+
expect(getByTestId(`${DEFAULT_TEST_ID}-btn-confirm`)).toHaveClass(
39+
isConfirmDanger ? 'btn-danger' : 'btn-primary'
40+
);
41+
}
42+
);
3843

3944
it('does not re-focus default button on re-render', async () => {
4045
const user = userEvent.setup();

packages/components/src/BasicModal.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ function BasicModal(props: BasicModalProps) {
5050
'data-testid': dataTestId,
5151
} = props;
5252

53-
const cancelButton = useRef<HTMLButtonElement>(null);
5453
const confirmButton = useRef<HTMLButtonElement>(null);
5554

5655
const disableModalCheckbox = useRef<HTMLInputElement>(null);
@@ -67,12 +66,8 @@ function BasicModal(props: BasicModalProps) {
6766
}, [onConfirm, onModalDisable]);
6867

6968
const onOpened = useCallback(() => {
70-
if (isConfirmDanger) {
71-
cancelButton.current?.focus();
72-
} else {
73-
confirmButton.current?.focus();
74-
}
75-
}, [isConfirmDanger]);
69+
confirmButton.current?.focus();
70+
}, []);
7671

7772
let modalBody = '';
7873
if (isOpen) {
@@ -124,7 +119,6 @@ function BasicModal(props: BasicModalProps) {
124119
kind="secondary"
125120
data-dismiss="modal"
126121
onClick={onCancel}
127-
ref={cancelButton}
128122
data-testid={
129123
dataTestId !== undefined ? `${dataTestId}-btn-cancel` : undefined
130124
}

0 commit comments

Comments
 (0)