Skip to content

Commit aba960f

Browse files
refactor(Modal): focus secondary button by default when Modal has type danger (#12006)
* docs(Modal): add example of selectorPrimaryFocus, Danger Modal * refactor(Modal): select secondary button by default when danger Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
1 parent 40be69e commit aba960f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/react/src/components/Modal/Modal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ const Modal = React.forwardRef(function Modal(
191191
const initialFocus = (focusContainerElement) => {
192192
const containerElement = focusContainerElement || innerModal.current;
193193
const primaryFocusElement = containerElement
194-
? containerElement.querySelector(selectorPrimaryFocus)
194+
? containerElement.querySelector(
195+
danger ? `.${prefix}--btn--secondary` : selectorPrimaryFocus
196+
)
195197
: null;
196198

197199
if (primaryFocusElement) {
@@ -211,7 +213,7 @@ const Modal = React.forwardRef(function Modal(
211213
if (open) {
212214
focusButton(innerModal.current);
213215
}
214-
}, [open, selectorPrimaryFocus]);
216+
}, [open, selectorPrimaryFocus, danger, prefix]);
215217

216218
const modalBody = (
217219
<div

packages/react/src/components/Modal/Modal.stories.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ export const Default = () => {
144144
);
145145
};
146146

147+
export const DangerModal = () => {
148+
return (
149+
<Modal
150+
open
151+
danger
152+
modalHeading="Are you sure you want to delete this custom domain?"
153+
modalLabel="Account resources"
154+
primaryButtonText="Delete"
155+
secondaryButtonText="Cancel"
156+
/>
157+
);
158+
};
159+
147160
export const Playground = () => {
148161
const { size, numberOfButtons, hasScrollingContent, ...modalProps } =
149162
props.modal();

0 commit comments

Comments
 (0)