ISSUE DESCRIPTION Accessibility: Focus moves to the wrong trigger when using "Open…
- User
ISSUE DESCRIPTION
Accessibility: Focus moves to the wrong trigger when using "Open programmatically" buttons
Current behavior
In the Alert Dialog, Dialog and Popover components, there is a variant that includes the option to use multiple triggers to open the dialogs. When using the "Open Programmatically" button to open the dialog/popup, then closing it, focus moves to a different control than the one that triggered the dialog/popup.
See:
- [Alert Dialog: Controlled mode with multiple triggers](https://base-ui.com/react/components/alert-dialog#controlled-mode-with-multiple-triggers
- Dialog: Controlled mode with multiple triggers
- Popover: Controlled mode with multiple triggers
This could cause failures against WCAG 2.2 Success Criterion 2.4.3 Focus Order when implemented.
Expected behavior
Keyboard focus should move back to the originating control (if available) when closing a dialog as long as a page refresh or redirection is not triggered.
If the control is no longer available, focus should move next to that originating control's position in the DOM.
Reproducible example
- Go to [Alert Dialog: Controlled mode with multiple triggers](https://base-ui.com/react/components/alert-dialog#controlled-mode-with-multiple-triggers
- Using keyboard, move focus to the "open programmatically" button
- Press Enter to activate the control and open the dialog
- Press Esc or activate the close button to close the dialog
- Note focus has moved back to the "Delete" button and not the "open programmatically" button as expected.
Base UI version
v1.2.0
Which browser are you using?
Chrome 145.0.7632.76
Which OS are you using?
Mac OS Tahoe 26.2
Which assistive tech are you using (if applicable)?
Keyboard
Additional context
Recommend keeping track of focus and returning it to the originating control.
Assistant
Let me start by exploring the repository structure to understand how it's organized and find the relevant components mentioned in the issue.
Assistant
Let me explore the repository structure more systematically.
Assistant
Now let me look at the packages folder where the components should be located.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /base-ui/packages/ </tool_call>
Assistant
Let me run the ls command to see the packages folder.
Assistant
Good, now let me look at the react package structure.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /base-ui/packages/react/src/ </tool_call>
Assistant
Let me run the ls command properly to see the react package structure.
Assistant
Now let me look at the alert-dialog component:
Assistant
Let me look at the alert-dialog root component and see how it handles focus management.
Assistant
Now let me look at the AlertDialogRoot component to understand how it handles focus when the dialog is opened and closed.
Assistant
I see that the AlertDialogRoot delegates to
useRenderDialogRoot. Let me look at the dialog root implementation to understand the focus management.<tool_call> <function=bash_terminal> <parameter=command> ls /base-ui/packages/react/src/dialog/root/ </tool_call>
Assistant
Let me run the ls command to see what's in the dialog root folder.
Assistant
Let me first read the useDialogRoot.ts file to understand the focus management.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/root/useDialogRoot.ts </tool_call>
Assistant
Let me try running the cat command properly to view the useDialogRoot.ts file.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/root/useDialogRoot.ts </tool_call>
Assistant
It seems like the terminal commands are not executing. Let me try again with a different approach.
Assistant
Good, now I can see the useDialogRoot file. I notice that it uses
useImplicitActiveTriggerandusePopupInteractionProps. Let me look at these functions to understand how focus management works.<tool_call> <function=bash_terminal> <parameter=command> find /base-ui/packages/react/src -name "popups*" -type f </tool_call>
Assistant
The terminal command is not being executed. Let me try to look for the popups utilities.
Assistant
Good, I can see there's a popups folder. Let me look at the popups folder to find the
useImplicitActiveTriggerandusePopupInteractionPropsfunctions.Assistant
I see the popups folder doesn't have an index.ts with the functions I'm looking for. Let me look for
useImplicitActiveTriggermore directly.Assistant
Now let me look at the popupStoreUtils.ts file to understand
useImplicitActiveTriggerandusePopupInteractionProps.Assistant
Let me also look at the store file to understand the full popup store state and how focus management works when closing:
Assistant
Now let me look at the FocusGuard component which is likely responsible for returning focus when the popup closes:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/utils/FocusGuard.tsx </tool_call>
Assistant
The terminal command seems to not be executing properly. Let me try again with the cat command for FocusGuard.tsx.
Assistant
Good, now let me look at the useTriggerFocusGuards.ts to see how focus guards are managed for triggers:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/utils/popups/useTriggerFocusGuards.ts </tool_call>
Assistant
The terminal command is not executing properly. Let me try a different approach - maybe I need to look at the test file for popupTriggerMap first to understand the issue better.
Assistant
Let me look for how the trigger's props handle focus restoration when closing. Let me search for where focus is returned when closing dialogs.
Assistant
I notice that the dialog store uses
activeTriggerElementin theonNestedDialogCloseevent. Let me look at the floating-ui-react hooks, especially theuseSyncedFloatingRootContext.tsfile to see how the popup stores the active trigger element when opening/closing.Assistant
Now let me look at the DialogStore to see how it handles the onNestedDialogClose callback when closing:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/store/DialogStore.ts </tool_call>
Assistant
The terminal seems to be having issues executing the cat command. Let me try a different approach - I'll try running a simpler command first to see if the terminal is working.
Assistant
Let me continue viewing the DialogStore.ts file to see how it handles closing and focus management:
<tool_call> <function=bash_terminal> <parameter=command> head -150 /base-ui/packages/react/src/dialog/store/DialogStore.ts </tool_call>
Assistant
The terminal command is not executing as expected. Let me try using the open tool to view the file instead, which might work differently.
Assistant
I can see the DialogStore. Now I understand the issue better. When the dialog is closed, the
setOpenmethod is called and it setsactiveTriggerElementbased on the eventDetails.trigger. When closing, it passes the oldactiveTriggerElementso it's not reset too early.The issue is about focus management when the dialog closes. Let me look for where focus restoration happens. Let me look at the Popover component to understand how focus is restored when closing.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/popover/popup/PopoverPopup.tsx </tool_call>
Assistant
The terminal command isn't executing. Let me try a different approach - I'll search for where focus restoration happens when a popup/dialog closes.
Assistant
Now I understand the issue better. Let me look at how focus is restored when a popup/dialog closes. The tests mention "should focus the trigger by default when closed". Let me search for where this focus restoration logic happens.
Assistant
The terminal seems to be having issues executing commands consistently. Let me try a different approach - let me try to find where the focus restoration logic is implemented by looking at the popup component files.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "returnFocus" /base-ui/packages/react/src --include=".ts" --include=".tsx" 2>/dev/null | head -30 </tool_call>
Assistant
The terminal command is not executing. Let me try using the open tool to view the PopoverPopup component to understand how focus is handled when closing.
Assistant
I can see that the PopoverPopup component uses
FloatingFocusManagerwithreturnFocus={finalFocus}andpreviousFocusableElement={activeTriggerElement}. Let me look at the FloatingFocusManager to understand how focus restoration works when closing.Now let me understand the issue better. Looking at the code:
- When a popup/dialog opens, the trigger that opened it is stored as
activeTriggerElement - When closing, the
FloatingFocusManagerwithreturnFocus={finalFocus}andpreviousFocusableElement={activeTriggerElement}is used to return focus
The issue is that when opening programmatically (e.g., using an "Open programmatically" button), the
activeTriggerElementis set to that button. But when closing, focus moves back to a different element.Let me look at the Dialog component to see how it handles this.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx 2>&1 | head -200 </tool_call>
- When a popup/dialog opens, the trigger that opened it is stored as
Assistant
Let me look at the Dialog popup component to see how it handles focus management when closing.
Assistant
Let me continue reading the DialogPopup component to see how it uses FloatingFocusManager.
Assistant
Now let me look at the FloatingFocusManager to understand how focus is returned when closing:
Assistant
Let me continue reading the FloatingFocusManager to understand how returnFocus works when closing.
Assistant
Now I understand the issue better. Let me look at the
getReturnElementfunction and how it determines where to return focus. The issue seems to be related to how theactiveTriggerElementis managed when opening programmatically.Let me look at the
useOpenStateTransitionsfunction to see how theactiveTriggerElementis cleared when unmounting:Assistant
I can see that when
forceUnmountis called, it clearsactiveTriggerElementby setting it tonull. This is the problem - when the dialog closes and then unmounts, theactiveTriggerElementis cleared, but the focus restoration should happen before unmounting.Let me look at how the focus is restored in
FloatingFocusManagermore closely, specifically how it usespreviousFocusableElementanddomReference.Assistant
The command failed. Let me try a different approach and search for the getReturnElement function.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "getReturnElement" /base-ui/packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx </tool_call>
Assistant
The terminal command is not being executed. Let me try a different approach and search for the getReturnElement function.
Assistant
Now let me see the lines around 780 to understand the getReturnElement function:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '770,830p' /base-ui/packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx </tool_call>
Assistant
Let me try using the open tool with the line number to view the relevant section of FloatingFocusManager:
Assistant
Now I understand the issue better. When
returnFocusistrue(default behavior), thegetReturnElementfunction returnsdomReference(which is the trigger element) if it's still connected, otherwise it returnsgetPreviouslyFocusedElement().The issue is that when the dialog is closed, the focus restoration should return to the active trigger that opened it. Let me check how
domReferenceis set in FloatingFocusManager and how it relates toactiveTriggerElement.Let me look at how the FloatingRootContext's domReference is set and updated when the dialog opens/closes:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/floating-ui-react/components/FloatingRootStore.ts </tool_call>
Assistant
The terminal command is not executing properly. Let me try a different approach to view the file.
Assistant
Now I need to look at the FloatingFocusManager to see how
domReferenceis set and used. Let me search for wheredomReferenceis defined:<tool_call> <function=bash_terminal> <parameter=command> grep -n "domReference" /base-ui/packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx | head -30 </tool_call>
Assistant
The terminal command is not executing. Let me try a different approach and use bash with a simpler command to find where domReference is defined.
Assistant
Let me understand the issue better. Let me check if DialogPopup passes
previousFocusableElementto FloatingFocusManager:Assistant
The terminal command exited with a non-zero code. Let me check if the grep command found any matches differently.
Assistant
The DialogPopup does not pass
previousFocusableElementto FloatingFocusManager, but the PopoverPopup does. Let me check this for the DialogPopup:Assistant
I see that DialogPopup does NOT pass
previousFocusableElementto FloatingFocusManager, but PopoverPopup does. Let me also check if the Alert Dialog (which uses DialogPopup) has the same issue.Now, I understand the issue better:
- When a dialog/popup is opened programmatically, the
activeTriggerElementis set to the programmatic trigger - When closing, the FloatingFocusManager uses
domReference(from FloatingRootStore) to return focus - The DialogPopup doesn't pass
previousFocusableElementto FloatingFocusManager, so focus restoration relies only ondomReference - The
domReferenceis set fromactiveTriggerElementvia theuseSyncedFloatingRootContexthook
Let me verify this by looking at the FloatingFocusManager usage in PopoverPopup:
- When a dialog/popup is opened programmatically, the
Assistant
Let me now look at the FloatingFocusManager to understand the flow better. The issue is that DialogPopup doesn't pass
previousFocusableElementto FloatingFocusManager. Let me check what the correct fix should be.Assistant
Let me trace the issue more carefully. I need to understand how
domReferenceis set when the dialog closes. Let me look at the FloatingRootStoreupdatemethod:Assistant
Let me look at the dispatchOpenChange method to understand how
domReferenceElementis updated: <tool_call> <function=bash_terminal> <parameter=command> sed -n '90,130p' /base-ui/packages/react/src/floating-ui-react/components/FloatingRootStore.ts 2>&1 </tool_call>Assistant
Let me continue reading the FloatingRootStore.ts to find the dispatchOpenChange method.
Assistant
Let me look at the
updatemethod to understand how thedomReferenceElementis set:<tool_call> <function=bash_terminal> <parameter=command> sed -n '1,50p' /base-ui/packages/react/src/floating-ui-react/components/FloatingRootStore.ts 2>&1 </tool_call>
Assistant
Let me understand the issue better. I need to look at how the focus restoration works when closing dialogs with multiple triggers. Let me first reproduce the issue by examining the code flow.
Assistant
Let me continue to read the FloatingRootStore.ts to understand the update method:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '30,90p' /base-ui/packages/react/src/floating-ui-react/components/FloatingRootStore.ts 2>&1 </tool_call>
Assistant
Let me try a different approach to read the file.
Assistant
Assistant
The terminal command is not executing. Let me try using the search_file tool to find the specific code I need.
Assistant
Assistant
The terminal command is not executing. Let me try a different approach to find the onClick handler in PopoverTrigger.
Assistant
The grep command didn't find any matches. Let me look at the PopoverTrigger component to understand how it handles the programmatic open.
Assistant
Now I can see the PopoverTrigger component. The trigger uses
useTriggerDataForwardingto forward trigger data to the store, and it usesclick.referencefromuseClickfor handling click events.The key insight here is that when a trigger is clicked, the
openMethodis set to the interaction type (e.g., 'click', 'keyboard'). This is done viainteractionTypePropsfromuseOpenMethodTriggerProps.Let me look at
useOpenMethodTriggerPropsto understand how the open method is tracked: <tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/utils/useOpenInteractionType.ts </tool_call>Assistant
The terminal command is not executing properly. Let me try a different approach.
Assistant
Now I understand better. The
useOpenInteractionTypehook tracks the interaction type that opened the component. When the component closes,setOpenMethod(null)is called.But I still need to understand the root cause of the issue. Let me look at how the Dialog triggers work and how the focus restoration is supposed to work.
Let me look at the Dialog trigger component to see how it's different from the Popover trigger:
<tool_call> <function=bash_terminal> <parameter=command> head -150 /base-ui/packages/react/src/dialog/trigger/DialogTrigger.tsx </tool_call>
Assistant
The terminal command is still not executing. Let me try running a simpler command first to verify the terminal is working.
Assistant
The terminal is working now. Let me view the DialogTrigger component.
<tool_call> <function=bash_terminal> <parameter=command> head -150 /base-ui/packages/react/src/dialog/trigger/DialogTrigger.tsx </tool_call>
Assistant
The terminal command isn't executing. Let me try a different approach - I'll use the open tool to view the file.
Assistant
Now I understand the issue better. Both DialogTrigger and PopoverTrigger use
useOpenMethodTriggerPropsto track the open method anduseTriggerDataForwardingto forward trigger data to the store.Let me trace through the flow again:
- When a trigger is clicked,
useOpenMethodTriggerPropssetsopenMethodto the interaction type useTriggerDataForwardingregisters the trigger and setsactiveTriggerElementto the trigger element- When the dialog closes, the
activeTriggerElementis preserved (viasetOpenTriggerState) - The FloatingFocusManager should return focus to the
domReferenceElementwhich should be synced fromactiveTriggerElement
But the issue is that DialogPopup doesn't pass
previousFocusableElementto FloatingFocusManager, while PopoverPopup does.Let me verify this by looking at both components again:
<tool_call> <function=bash_terminal> <parameter=command> grep -A 10 "FloatingFocusManager" /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
- When a trigger is clicked,
Assistant
The terminal command is not executing again. Let me try a different approach.
Assistant
Assistant
The terminal command is not executing. Let me try a different approach to understand the issue.
Assistant
Let me look at how
openInteractionTypeis used inFloatingFocusManagerto understand how focus is handled:Assistant
Let me understand the issue more clearly by looking at how
domReferenceis used in focus restoration. The key is to understand whendomReferencemight be null or disconnected when the dialog closes.<tool_call> <function=bash_terminal> <parameter=command> sed -n '790,810p' /base-ui/packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx </tool_call>
Assistant
Let me try running the command again to see the focus restoration code.
Assistant
Now I understand the issue better. When
returnFocusistrue(the default), thegetReturnElementfunction returnsdomReferenceif it's connected, otherwise it falls back togetPreviouslyFocusedElement().The issue is that
domReferencecomes fromstore.useState('domReferenceElement'), which is synced fromactiveTriggerElementviauseSyncedFloatingRootContext.Let me trace through the issue:
- When the "Open programmatically" button is clicked,
activeTriggerElementis set to null (since it's a programmatic open) - The dialog opens,
domReferenceis null - When closing,
getReturnElement()checks ifdomReference?.isConnected, butdomReferenceis null - So it falls back to
getPreviouslyFocusedElement()
But
getPreviouslyFocusedElement()should return the element that was focused before the popup opened, which should be the "Open programmatically" button.Wait, let me look at how
previouslyFocusedElementsis populated:- When the "Open programmatically" button is clicked,
Assistant
Let me look at where
addPreviouslyFocusedElementis called to understand when the focus history is recorded.Assistant
Now I understand the flow better. The
previouslyFocusedElementis captured in auseIsoLayoutEffectwhen the component mounts. This captures the currently focused element when the popup is opened.But there's an issue -
previouslyFocusedElementis captured once when the component mounts, not every time the popup opens. If the popup opens and closes multiple times, the samepreviouslyFocusedElementwill be used.But more importantly, I need to understand how
domReferenceis set. Let me look atuseSyncedFloatingRootContext:Assistant
The terminal is working. Let me continue reading to see the effect that syncs
domReferenceElement:<tool_call> <function=bash_terminal> <parameter=command> sed -n '75,100p' /base-ui/packages/react/src/floating-ui-react/hooks/useSyncedFloatingRootContext.ts </tool_call>
Assistant
The terminal command is not executing. Let me try running the command again.
Assistant
Now I understand the issue. Looking at the
useSyncedFloatingRootContexthook:if (isElement(referenceElement)) { valuesToSync.domReferenceElement = referenceElement; }This means
domReferenceElementis only set ifreferenceElement(which isactiveTriggerElement) is an element. IfactiveTriggerElementisnull,domReferenceElementis NOT updated.So when opening programmatically:
activeTriggerElementis set tonullreferenceElementinuseSyncedFloatingRootContextisnulldomReferenceElementis not updated (keeps the old value or isnull)- When closing, might be or have an old value
Assistant
The terminal command is not executing. Let me try a different approach to find the DialogHandle file.
Assistant
Assistant
Let me look at the DialogPopup component to understand its current structure and where to add the
previousFocusableElementprop.Assistant
Now I understand the issue. Looking at the
DialogPopupcomponent, I can see that it does NOT passpreviousFocusableElementtoFloatingFocusManager, whilePopoverPopupdoes.Looking at
PopoverPopup:previousFocusableElement={ isHTMLElement(activeTriggerElement) ? activeTriggerElement : undefined }The fix is to add
previousFocusableElementtoDialogPopupas well. This will ensure that when the dialog closes, focus is returned to the correct trigger element.Let me implement this fix:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
Assistant
Now I need to modify the
DialogPopupcomponent to addpreviousFocusableElementprop. Let me also check the Alert Dialog popup to see if it needs the same fix:Assistant
The
AlertDialogRootusesuseRenderDialogRootwhich delegates toDialogRoot. So the Alert Dialog popup is the same as the Dialog popup. Let me check if the Alert Dialog has its own popup component:Assistant
Let me look at the alert-dialog root to see if there's a separate popup component.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/root/useRenderDialogRoot.tsx </tool_call>
Assistant
The terminal command is not executing. Let me try running it again.
Assistant
Now I understand the structure. The
useRenderDialogRootfunction is used by both Dialog and AlertDialog. The popup component isDialogPopup, which is used by both Dialog and AlertDialog.Now let me check the drawer component to see if it also needs the same fix:
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/drawer/popup/DrawerPopup.tsx 2>&1 | grep -A 20 "FloatingFocusManager" </tool_call>
Assistant
Let me try running the command again to see if the FloatingFocusManager is used in DrawerPopup.
Assistant
Let me look at the DrawerPopup to see how it uses FloatingFocusManager:
Assistant
I see that both
DialogPopupandDrawerPopupdon't passpreviousFocusableElementtoFloatingFocusManager, butPopoverPopupdoes. This is likely the root cause of the issue.Now let me fix the
DialogPopupcomponent by adding thepreviousFocusableElementprop. First, I need to add the import forisHTMLElementand add theactiveTriggerElementstate.Assistant
Now I understand the issue. The
DialogPopupcomponent doesn't passpreviousFocusableElementtoFloatingFocusManager, whilePopoverPopupdoes. This causes focus to not return to the correct trigger element when closing.Let me fix the
DialogPopupcomponent by adding thepreviousFocusableElementprop:Assistant
Now let me add the
activeTriggerElementstate and update theFloatingFocusManagerto passpreviousFocusableElement. First, let me check the current state declarations:Assistant
Now I need to add
activeTriggerElementto the state declarations. Let me add it afterfloatingId:Assistant
Let me verify the change was applied correctly.
Assistant
Good, the
activeTriggerElementstate is now added. Now I need to update theFloatingFocusManagerto passpreviousFocusableElement. Let me find where theFloatingFocusManageris used and update it.<tool_call> <function=bash_terminal> <parameter=command> sed -n '125,145p' /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx 2>&1 </tool_call>
Assistant
Let me find the FloatingFocusManager section in the file and update it.
Assistant
Now let me look at the FloatingFocusManager section to update it:
Assistant
Now I need to add the
previousFocusableElementprop to theFloatingFocusManager. Let me update the file using the edit command:<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/ restoreFocus="popup"/ restoreFocus="popup"\n previousFocusableElement={\n isHTMLElement(activeTriggerElement) ? activeTriggerElement : undefined\n }/' /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
Assistant
Let me try a different approach to edit the file.
Assistant
Now I can see the exact content. Let me use sed to add the
previousFocusableElementprop. First, let me create a backup and then modify the file.<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/ restoreFocus="popup"/ restoreFocus="popup"\n previousFocusableElement={\n isHTMLElement(activeTriggerElement) ? activeTriggerElement : undefined\n }/' /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
Assistant
The terminal command is not executing. Let me try using the open tool to edit the file directly.
Assistant
Let me try a different approach - I'll use the open tool to view and then the edit tool to modify the file.
Assistant
Now I know the line number. Let me use sed to insert the new lines after line 130:
Assistant
Let me verify the change was applied:
Assistant
The
previousFocusableElementprop has been added toDialogPopup. Now I need to apply the same fix toDrawerPopup. Let me first check the current state ofDrawerPopupand then add theactiveTriggerElementstate and thepreviousFocusableElementprop.Assistant
The
activeTriggerElementis not used inDrawerPopup. Let me first add the import forisHTMLElementand then add theactiveTriggerElementstate.Assistant
Now let me add the import for
isHTMLElementafter line 9:Assistant
Now let me find where to add the
activeTriggerElementstate. Let me look at the state declarations inDrawerPopup:Assistant
Now let me add the
activeTriggerElementstate. I'll add it aftertitleElementId:Assistant
Now let me find the
FloatingFocusManagersection inDrawerPopupto add thepreviousFocusableElementprop:Assistant
Now let me add the
previousFocusableElementprop after line 412:Assistant
Let me verify the change was applied:
Assistant
Now I need to verify that the import for
isHTMLElementwas added correctly. Let me check:Assistant
I notice the import is missing the semicolon. Let me fix that:
Assistant
Now let me verify the import is correct:
Assistant
Now I also need to check if the
activeTriggerElementstate is properly added:Assistant
The changes look good. Now let me also check the DialogPopup to make sure all changes are correct:
Assistant
I see the import for
isHTMLElementin DialogPopup is missing the semicolon. Let me fix that:Assistant
Let me verify the fix:
Assistant
Now let me verify that the
activeTriggerElementstate is properly added in DialogPopup:<tool_call> <function=bash_terminal> <parameter=command> grep -n "activeTriggerElement" /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx 2>&1 </tool_call>
Assistant
Let me run the grep command to verify the activeTriggerElement state was added to DialogPopup.
Assistant
The
activeTriggerElementstate is added to DialogPopup. Now let me run the existing tests to make sure the changes don't break anything:Assistant
The pnpm command timed out. Let me try running a simpler test to verify the syntax is correct:
Assistant
The command timed out again. Let me try to check the syntax by using node to parse the TypeScript file:
Assistant
Good, the TypeScript syntax is valid. Let me also check the DrawerPopup:
Assistant
Both files have valid TypeScript syntax. Now let me verify that the fix is complete by looking at the final state of both files:
Assistant
Now let me check the FloatingFocusManager section in DialogPopup:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '120,145p' /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
Assistant
The terminal command is not executing. Let me try again with a simpler command.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '120,145p' /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx </tool_call>
Assistant
The terminal command is not executing consistently. Let me try a different approach to verify the changes.
Assistant
I've made changes to fix the focus management issue in Dialog and Drawer components. Let me verify my changes are correct and complete.
<tool_call> <function=bash_terminal> <parameter=command> cat /base-ui/packages/react/src/dialog/popup/DialogPopup.tsx | grep -A 5 "restoreFocus" </tool_call>
Assistant
The terminal command is not executing again. Let me try a simpler approach to verify the changes.
Assistant
Let me see what's after the restoreFocus line:
Assistant
The changes look correct. Now let me also verify the DrawerPopup changes:
Assistant
Both files have the
previousFocusableElementprop added correctly. Now let me also verify that theactiveTriggerElementstate is present in both files:Assistant
Both files have the
activeTriggerElementstate and thepreviousFocusableElementprop added correctly. Now let me also check if there are any tests related to this functionality that I should run to verify the fix doesn't break anything. Let me check if the test file exists and run a simple syntax check:<tool_call> <function=bash_terminal> <parameter=command> ls /base-ui/packages/react/src/dialog/popup/DialogPopup.test.tsx </tool_call>
Assistant
The terminal command isn't executing. Let me try again.
Assistant
Good, the test file exists. Let me also check the drawer popup test file:
Assistant
Good. Now let me create a simple test script to verify that the TypeScript compiles correctly without running the full test suite:
Assistant
Now both files have valid TypeScript syntax. Let me review the changes I made:
-
DialogPopup.tsx:
- Added import for
isHTMLElementfrom@floating-ui/utils/dom - Added
activeTriggerElementstate from the store - Added
previousFocusableElementprop toFloatingFocusManager
- Added import for
-
DrawerPopup.tsx:
- Added import for
isHTMLElementfrom@floating-ui/utils/dom - Added
activeTriggerElementstate from the store - Added
previousFocusableElementprop toFloatingFocusManager
- Added import for
These changes ensure that when a dialog or drawer is closed, focus returns to the correct trigger element that opened it. The
previousFocusableElementprop tellsFloatingFocusManagerwhich element to restore focus to when closing.Now let me submit the changes:
<tool_call> <function=bash_terminal> <parameter=command> git diff --stat </tool_call>
-
Assistant
The terminal command is not executing. Let me try again with a different approach.
Assistant
Let me now view the diff to see the exact changes:
Assistant
Now let me also see the diff for the DrawerPopup.tsx file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.