Skip to content

Commit

Permalink
feature: isConfirmDangerProp
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Feb 24, 2023
1 parent 144605a commit b6a3bae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/components/src/BasicModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface BasicModalProps {
cancelButtonText?: string;
confirmButtonText?: string;
discardButtonText?: string;
isConfirmDanger?: boolean;
children?: React.ReactNode;
'data-testid'?: string;
}
Expand Down Expand Up @@ -44,10 +45,12 @@ function BasicModal(props: BasicModalProps) {
cancelButtonText = 'Cancel',
confirmButtonText = 'Okay',
discardButtonText = 'Discard',
isConfirmDanger = false,
children,
'data-testid': dataTestId,
} = props;

const cancelButton = useRef<HTMLButtonElement>(null);
const confirmButton = useRef<HTMLButtonElement>(null);

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

const onOpened = useCallback(() => {
confirmButton.current?.focus();
}, []);
if (isConfirmDanger) {
cancelButton.current?.focus();
} else {
confirmButton.current?.focus();
}
}, [isConfirmDanger]);

let modalBody = '';
if (isOpen) {
Expand Down Expand Up @@ -117,6 +124,7 @@ function BasicModal(props: BasicModalProps) {
kind="secondary"
data-dismiss="modal"
onClick={onCancel}
ref={cancelButton}
data-testid={
dataTestId !== undefined ? `${dataTestId}-btn-cancel` : undefined
}
Expand All @@ -126,7 +134,7 @@ function BasicModal(props: BasicModalProps) {
)}
<ButtonGroup>
<Button
kind="primary"
kind={isConfirmDanger ? 'danger' : 'primary'}
onClick={onConfirmClicked}
ref={confirmButton}
data-testid={
Expand Down

0 comments on commit b6a3bae

Please sign in to comment.