Skip to content

Commit 57b9b54

Browse files
authored
fix(MessageBox): always create valid id for String action button (#7091)
1 parent 65415df commit 57b9b54

File tree

1 file changed

+4
-4
lines changed
  • packages/main/src/components/MessageBox

1 file changed

+4
-4
lines changed

packages/main/src/components/MessageBox/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ const MessageBox = forwardRef<DialogDomRef, MessageBoxPropTypes>((props, ref) =>
206206
const internalActions = getActions(actions, type);
207207

208208
const getInitialFocus = () => {
209-
const actionToFocus = internalActions.find((action) => action === initialFocus);
210-
if (typeof actionToFocus === 'string') {
211-
return `${messageBoxId}-action-${actionToFocus}`;
209+
const index = internalActions.findIndex((action) => action === initialFocus);
210+
if (index !== -1 && typeof internalActions[index] === 'string') {
211+
return `${messageBoxId}-action-${index}`;
212212
}
213213
return initialFocus;
214214
};
@@ -259,7 +259,7 @@ const MessageBox = forwardRef<DialogDomRef, MessageBoxPropTypes>((props, ref) =>
259259
if (typeof action === 'string') {
260260
return (
261261
<Button
262-
id={`${messageBoxId}-action-${action}`}
262+
id={`${messageBoxId}-action-${index}`}
263263
key={`${action}-${index}`}
264264
design={emphasizedAction === action ? ButtonDesign.Emphasized : ButtonDesign.Transparent}
265265
onClick={handleOnClose}

0 commit comments

Comments
 (0)