You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Awaiting Payment 26th Sept] [$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters. #48108
changed the title [-]Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/-][+][$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/+]on Aug 27, 2024
This is related to focus trap. It seems like the top back button is selected when Enter is pressed, which navigates the user back. This also seems to happen in other flows, e.g. Submit expense
Edited by proposal-police: This proposal was edited at 2024-08-27 18:38:39 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Focus is set on the back button when navigating to the filter page using keyboard
What is the root cause of that problem?
when the filter page is first rendered, the focus trap keeps the focus on the back button and doesn't move to the confirm button.
we solved this issue in the submit report confirmation page by bluring the active element so the focus moves from the back header to the button after the timeout:
When subscribing to the keyboard short, we can check if pressOnEnter is true or not and based on that we will call blurActiveElement. After making this change we can remove all the instances which is used in a component to remove the focus from the back button.
Edited by proposal-police: This proposal was edited at 2024-08-28 08:54:02 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When entering a search filter on the advanced search page, pressing Enter and then pressing Enter again does not proceed with the search request and ends up clearing the search filter.
What is the root cause of the problem?
When the screen is mounted, the focus trap sets the initialFocus to the first focusable element:
Since the document's activeElement is outside of the screen (the view result button is not focused), the initialFocus will return undefined and will focus the first element (in this case, the header back button). When the user presses Enter, the back button is pressed instead of the View result button.
What changes do you think we should make in order to solve the problem?
The focus trap already listens for the focus event and checks whether the focused element is within the element to which it is attached (in this case, within the screen). It will automatically move the focus inside the screen if it is outside. For example, when the user presses the Tab key, the focus trap will focus the first element of the screen if the current active element is outside the screen. Therefore, we do not need the focus trap to auto-focus when the screen is mounted. The auto-focus behavior of the focus trap will also interfere with the auto-focus applied to elements inside the screen.
We can disable the initialFocus. In the FocusTrapForScreen options:
The focus trap already listens for the focus event and will check whether the focused element is inside the element to which it is attached (in this case, inside the screen) and will automatically move the focus inside the screen if it is outside.
The code change (in legacy mode, to test set USE_REACT_STRICT_MODE to false) could be:
changed the title [-][$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/-][+][Awaiting Payment 26th Sept] [$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/+]on Sep 23, 2024
Activity
melvin-bot commentedon Aug 27, 2024
Triggered auto assignment to @trjExpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.melvin-bot commentedon Aug 27, 2024
Job added to Upwork: https://www.upwork.com/jobs/~01e1f39a3a6d7c0f4a
[-]Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/-][+][$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/+]melvin-bot commentedon Aug 27, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @alitoshmatov (
External)luacmartins commentedon Aug 27, 2024
This is related to focus trap. It seems like the top back button is selected when
Enteris pressed, which navigates the user back. This also seems to happen in other flows, e.g. Submit expenseabzokhattab commentedon Aug 27, 2024
Edited by proposal-police: This proposal was edited at 2024-08-27 18:38:39 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Focus is set on the back button when navigating to the filter page using keyboard
What is the root cause of that problem?
when the filter page is first rendered, the focus trap keeps the focus on the back button and doesn't move to the confirm button.
we solved this issue in the submit report confirmation page by bluring the active element so the focus moves from the back header to the button after the timeout:
App/src/components/MoneyRequestConfirmationList.tsx
Lines 815 to 825 in 735101a
What changes do you think we should make in order to solve the problem?
we should do the same in the filter page to keep both flows consistent and don't introduce breaking changes to the focus trap logic.
Optional
this logic can be moved to a hook and used when needed to avoid code duplication
result
Screen.Recording.2024-08-27.at.8.47.38.PM.mov
Krishna2323 commentedon Aug 27, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.
This problem was faced in the submit expense flow, to solve that issue we manually moved removed the focus from the back button.
App/src/components/MoneyRequestConfirmationList.tsx
Lines 815 to 825 in e5b6cef
What is the root cause of that problem?
Due to the focus trap the focus is set to the first focus element instead of the submit button.
What changes do you think we should make in order to solve the problem?
blurActiveElementon every page. I suggest to add the function in the button component.App/src/components/Button/index.tsx
Lines 142 to 156 in e5b6cef
pressOnEnteris true or not and based on that we will callblurActiveElement. After making this change we can remove all the instances which is used in a component to remove the focus from the back button.What alternative solutions did you explore? (Optional)
Result
tsa321 commentedon Aug 28, 2024
Edited by proposal-police: This proposal was edited at 2024-08-28 08:54:02 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When entering a search filter on the advanced search page, pressing
Enterand then pressingEnteragain does not proceed with the search request and ends up clearing the search filter.What is the root cause of the problem?
When the screen is mounted, the focus trap sets the
initialFocusto the first focusable element:App/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Lines 49 to 58 in ac5ee2e
Since the document's
activeElementis outside of the screen (theview resultbutton is not focused), theinitialFocuswill returnundefinedand will focus the first element (in this case, the header back button). When the user pressesEnter, the back button is pressed instead of theView resultbutton.What changes do you think we should make in order to solve the problem?
The focus trap already listens for the focus event and checks whether the focused element is within the element to which it is attached (in this case, within the screen). It will automatically move the focus inside the screen if it is outside. For example, when the user presses the
Tabkey, the focus trap will focus the first element of the screen if the current active element is outside the screen. Therefore, we do not need the focus trap to auto-focus when the screen is mounted. The auto-focus behavior of the focus trap will also interfere with the auto-focus applied to elements inside the screen.We can disable the
initialFocus. In theFocusTrapForScreenoptions:App/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Lines 44 to 45 in 59741d8
we could add an
onActivateproperty with the function:() => document?.activeElement?.blur(). Then, ininitialFocus:App/src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Lines 49 to 59 in 59741d8
we should always set it to
falseorreturn false.The focus trap already listens for the focus event and will check whether the focused element is inside the element to which it is attached (in this case, inside the screen) and will automatically move the focus inside the screen if it is outside.
The code change (in legacy mode, to test set
USE_REACT_STRICT_MODEtofalse) could be:focusTrapOptions={{ + onActivate: () => { + document?.activeElement?.blur(); + }, trapStack: sharedTrapStack, allowOutsideClick: true, fallbackFocus: document.body, delayInitialFocus: CONST.ANIMATED_TRANSITION, initialFocus: (focusTrapContainers) => { - if (!canFocusInputOnScreenFocus()) { - return false; - } - const isFocusedElementInsideContainer = focusTrapContainers?.some((container) => container.contains(document.activeElement)); - if (isFocusedElementInsideContainer) { - return false; - } - return undefined; + return false; }, setReturnFocus: (element) => { + return false; - if (document.activeElement && document.activeElement !== document.body) { - return false; - } - return element; }, ...(focusTrapSettings?.focusTrapOptions ?? {}), }}What alternative solutions did you explore? (2)
On other pages, we use
useAutoFocusInput();as shown in:App/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
Line 43 in 3e5da78
App/src/pages/OnboardingWork/BaseOnboardingWork.tsx
Line 35 in 3e5da78
App/src/pages/iou/request/step/IOURequestStepMerchant.tsx
Line 58 in 3e5da78
etc..
We could also use it for
AdvancedSearchFilters. To do this, we can add:Then, in:
App/src/pages/Search/AdvancedSearchFilters.tsx
Lines 316 to 317 in 3e5da78
we add
buttonRef={inputCallbackRef}. Additionally, since the hook is general and not limited to text input, we can rename it if necessary.30 remaining items
melvin-bot commentedon Sep 18, 2024
[-][$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/-][+][Awaiting Payment 26th Sept] [$250] Selecting a filter and using keyboard return on the filter confirmation screen ends up clearing filters.[/+]trjExpensify commentedon Sep 23, 2024
PR on prod, updated the title to reflect the payment hold.
melvin-bot commentedon Sep 24, 2024
@suneox @trjExpensify @luacmartins @alitoshmatov this issue is now 4 weeks old, please consider:
Thanks!
trjExpensify commentedon Sep 25, 2024
Go away, melvin.
trjExpensify commentedon Sep 26, 2024
Payment summary as follows:
Paid, closing!