Skip to content

Commit e0e636b

Browse files
authored
fix(MessageBox): always create valid id for String action button (#7113)
cherry-picked: 57b9b54
1 parent 9e3054e commit e0e636b

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
@@ -200,9 +200,9 @@ const MessageBox = forwardRef<DialogDomRef, MessageBoxPropTypes>((props, ref) =>
200200
const internalActions = getActions(actions, type);
201201

202202
const getInitialFocus = () => {
203-
const actionToFocus = internalActions.find((action) => action === initialFocus);
204-
if (typeof actionToFocus === 'string') {
205-
return `${messageBoxId}-action-${actionToFocus}`;
203+
const index = internalActions.findIndex((action) => action === initialFocus);
204+
if (index !== -1 && typeof internalActions[index] === 'string') {
205+
return `${messageBoxId}-action-${index}`;
206206
}
207207
return initialFocus;
208208
};
@@ -253,7 +253,7 @@ const MessageBox = forwardRef<DialogDomRef, MessageBoxPropTypes>((props, ref) =>
253253
if (typeof action === 'string') {
254254
return (
255255
<Button
256-
id={`${messageBoxId}-action-${action}`}
256+
id={`${messageBoxId}-action-${index}`}
257257
key={`${action}-${index}`}
258258
design={emphasizedAction === action ? ButtonDesign.Emphasized : ButtonDesign.Transparent}
259259
onClick={handleOnClose}

0 commit comments

Comments
 (0)