Skip to content

[ML] Anomaly Detection: Restore focus to row actions menu in job management table#230170

Merged
rbrtj merged 5 commits intoelastic:mainfrom
rbrtj:ml-restore-focus-a11y-fix
Aug 5, 2025
Merged

[ML] Anomaly Detection: Restore focus to row actions menu in job management table#230170
rbrtj merged 5 commits intoelastic:mainfrom
rbrtj:ml-restore-focus-a11y-fix

Conversation

@rbrtj
Copy link
Contributor

@rbrtj rbrtj commented Aug 1, 2025

Fix for: #195017
This PR fixes an issue with focus restoration, where opening a Flyout or Modal from the context action menu doesn't properly restore focus. Unfortunately, this isn't fixable on the Eui side at the moment, so to address this, we need to manually restore focus to the action button. It creates reusable helpers responsible for creating focusTrapProps for flyouts and manually restoring focus for Modals, as this issue occurs whenever a Flyout or Modal is triggered from the context action menu.
After fix:

Screen.Recording.2025-08-01.at.10.33.49.mov
);

return (
<EuiPortal>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was obsolete, EuiFlyout already comes with a Portal

@rbrtj rbrtj self-assigned this Aug 1, 2025
@rbrtj rbrtj added :ml release_note:skip Skip the PR/issue when compiling release notes Team:ML Team label for ML (also use :ml) t// backport:version Backport to applied version labels v9.2.0 v8.17.10 v8.18.5 v8.19.1 v9.0.5 labels Aug 1, 2025
@rbrtj rbrtj marked this pull request as ready for review August 1, 2025 08:44
@rbrtj rbrtj requested review from a team as code owners August 1, 2025 08:44
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested (Chrome and Firefox) and confirmed the focus is now being restored the menu correctly.

As discussed, the same fix should be applied to the bulk actions menu, but this can be done in a follow-up.

Screenshot 2025-08-01 at 13 02 20
Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments, but on the whole LGTM

end: number;
onClose: () => void;
onModelSnapshotAnnotationClick?: (modelSnapshot: ModelSnapshot) => void;
focusTrapProps?: EuiFlyoutProps['focusTrapProps'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're using this type a lot, maybe it's worth exporting it from create_focus_trap_props.ts
e.g.

export type FocusTrapProps = EuiFlyoutResizableProps['focusTrapProps'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 460629f

};

export const createJobActionFocusRestoration = (jobId: string) => {
const actionButton = document.getElementById(`${jobId}-actions`)?.querySelector('button');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I think this could be:

Suggested change
const actionButton = document.getElementById(`${jobId}-actions`)?.querySelector('button');
const actionButton = document.querySelector(`#${jobId}-actions button`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that actionButton would be typed as Element, which is a base class for e.g., HTMLElement, and doesn't have the focus method typed. I think it's better to stick with the current implementation rather than asserting the type or adding a type guard

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
ml 2497 2499 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 2.6MB 2.6MB +109.0B
datasetQuality 421.2KB 421.3KB +109.0B
discover 1.1MB 1.1MB +109.0B
infra 1.0MB 1.0MB +109.0B
ml 5.3MB 5.3MB +1.1KB
monitoring 631.0KB 631.1KB +109.0B
observability 1.3MB 1.3MB +109.0B
slo 979.5KB 979.6KB +109.0B
synthetics 1.0MB 1.0MB +109.0B
transform 622.4KB 622.5KB +109.0B
uptime 491.5KB 491.6KB +109.0B
total +2.2KB

History

cc @rbrtj

@rbrtj rbrtj merged commit 742ddef into elastic:main Aug 5, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.18, 8.19, 9.0

https://github.com/elastic/kibana/actions/runs/16748055219

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.17 Backport failed because of merge conflicts
8.18 Backport failed because of merge conflicts
8.19 Backport failed because of merge conflicts
9.0 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 230170

Questions ?

Please refer to the Backport tool documentation

delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
…0170)

Fix for: elastic#195017
This PR fixes an issue with focus restoration, where opening a Flyout or
Modal from the context action menu doesn't properly restore focus.
Unfortunately, this isn't fixable on the Eui side at the moment, so to
address this, we need to manually restore focus to the action button. It
creates reusable helpers responsible for creating `focusTrapProps` for
flyouts and manually restoring focus for Modals, as this issue occurs
whenever a Flyout or Modal is triggered from the context action menu.
After fix:






https://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.1

https://github.com/elastic/kibana/actions/runs/16772663283

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
9.1 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 230170

Questions ?

Please refer to the Backport tool documentation

@rbrtj
Copy link
Contributor Author

rbrtj commented Aug 6, 2025

💚 All backports created successfully

Status Branch Result
9.1

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

rbrtj added a commit to rbrtj/kibana that referenced this pull request Aug 6, 2025
…0170)

Fix for: elastic#195017
This PR fixes an issue with focus restoration, where opening a Flyout or
Modal from the context action menu doesn't properly restore focus.
Unfortunately, this isn't fixable on the Eui side at the moment, so to
address this, we need to manually restore focus to the action button. It
creates reusable helpers responsible for creating `focusTrapProps` for
flyouts and manually restoring focus for Modals, as this issue occurs
whenever a Flyout or Modal is triggered from the context action menu.
After fix:

https://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf
(cherry picked from commit 742ddef)

# Conflicts:
#	src/platform/packages/shared/response-ops/rule_form/flyout/rule_form_flyout.tsx
@rbrtj rbrtj added the v9.1.1 label Aug 6, 2025
rbrtj added a commit that referenced this pull request Aug 6, 2025
) (#230735)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[ML] Anomaly Detection: Restore focus to row actions menu
(#230170)](#230170)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-08-05T10:55:36Z","message":"[ML]
Anomaly Detection: Restore focus to row actions menu (#230170)\n\nFix
for: https://github.com/elastic/kibana/issues/195017\nThis PR fixes an
issue with focus restoration, where opening a Flyout or\nModal from the
context action menu doesn't properly restore focus.\nUnfortunately, this
isn't fixable on the Eui side at the moment, so to\naddress this, we
need to manually restore focus to the action button. It\ncreates
reusable helpers responsible for creating `focusTrapProps` for\nflyouts
and manually restoring focus for Modals, as this issue occurs\nwhenever
a Flyout or Modal is triggered from the context action menu.\nAfter
fix:\n\n\n\n\n\n\nhttps://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf","sha":"742ddef446a90668868a566b2eef5916552425e8","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","Team:ML","backport:prev-minor","v9.2.0"],"title":"[ML]
Anomaly Detection: Restore focus to row actions
menu","number":230170,"url":"https://github.com/elastic/kibana/pull/230170","mergeCommit":{"message":"[ML]
Anomaly Detection: Restore focus to row actions menu (#230170)\n\nFix
for: https://github.com/elastic/kibana/issues/195017\nThis PR fixes an
issue with focus restoration, where opening a Flyout or\nModal from the
context action menu doesn't properly restore focus.\nUnfortunately, this
isn't fixable on the Eui side at the moment, so to\naddress this, we
need to manually restore focus to the action button. It\ncreates
reusable helpers responsible for creating `focusTrapProps` for\nflyouts
and manually restoring focus for Modals, as this issue occurs\nwhenever
a Flyout or Modal is triggered from the context action menu.\nAfter
fix:\n\n\n\n\n\n\nhttps://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf","sha":"742ddef446a90668868a566b2eef5916552425e8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/230170","number":230170,"mergeCommit":{"message":"[ML]
Anomaly Detection: Restore focus to row actions menu (#230170)\n\nFix
for: https://github.com/elastic/kibana/issues/195017\nThis PR fixes an
issue with focus restoration, where opening a Flyout or\nModal from the
context action menu doesn't properly restore focus.\nUnfortunately, this
isn't fixable on the Eui side at the moment, so to\naddress this, we
need to manually restore focus to the action button. It\ncreates
reusable helpers responsible for creating `focusTrapProps` for\nflyouts
and manually restoring focus for Modals, as this issue occurs\nwhenever
a Flyout or Modal is triggered from the context action menu.\nAfter
fix:\n\n\n\n\n\n\nhttps://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf","sha":"742ddef446a90668868a566b2eef5916552425e8"}}]}]
BACKPORT-->
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
@mistic mistic added v9.1.2 and removed v9.1.1 labels Aug 7, 2025
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
…0170)

Fix for: elastic#195017
This PR fixes an issue with focus restoration, where opening a Flyout or
Modal from the context action menu doesn't properly restore focus.
Unfortunately, this isn't fixable on the Eui side at the moment, so to
address this, we need to manually restore focus to the action button. It
creates reusable helpers responsible for creating `focusTrapProps` for
flyouts and manually restoring focus for Modals, as this issue occurs
whenever a Flyout or Modal is triggered from the context action menu.
After fix:






https://github.com/user-attachments/assets/19c259e0-1c8b-4304-bcdd-918d4e0d45cf
@peteharverson peteharverson added the Feature:Anomaly Detection ML anomaly detection label Aug 20, 2025
@peteharverson peteharverson changed the title [ML] Anomaly Detection: Restore focus to row actions menu Aug 20, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-accessibility (Project:Accessibility)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Anomaly Detection ML anomaly detection :ml Project:Accessibility release_note:skip Skip the PR/issue when compiling release notes Team:ML Team label for ML (also use :ml) t// v9.1.2 v9.2.0

7 participants