Skip to content

Commit

Permalink
[8.13] fix: [Rules > Detection rules][AXE-CORE]: Interactive contr…
Browse files Browse the repository at this point in the history
…ols must not be nested (elastic#177710) (elastic#178240)

# Backport

This will backport the following commits from `main` to `8.13`:
- [fix: [Rules > Detection rules][AXE-CORE]: Interactive controls
must not be nested
(elastic#177710)](elastic#177710)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Alexey
Antonov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-03-07T15:59:02Z","message":"fix:
[Rules > Detection rules][AXE-CORE]: Interactive controls must not be
nested (elastic#177710)\n\nCloses:
https://github.com/elastic/security-team/issues/8567\r\nCloses:
https://github.com/elastic/security-team/issues/8627\r\n\r\n##
Summary\r\n\r\nThe [axe browser plugin](https://deque.com/axe) is
reporting a nested\r\nbutton (interactive control). This appears to be a
tooltip nested within\r\na table sorting button. This pull request
addresses that issue in the\r\nsame manner as with
`EuiIconTip`.\r\n\r\nBy the way, I discovered a couple of accessibility
(a11y) issues in\r\nwhich also were fixed:\r\n- [x] Tooltip icon for
TableHeaderTooltipCell wasn't available for\r\nkeyboard navigation. It
was updated to use `EuiIconTip`.\r\n- [x] Set one color to \"subdued\"
for all tooltip icons.\r\n\r\n### Screens\r\n\r\n#### Axe report
\r\n\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/20072247/5bc57702-f63a-4c6c-9f9d-341a7ebaebc5\">\r\n\r\n\r\n####
Keyboard navigation
\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/20072247/8cd32a42-a711-42e4-ae11-badca4038fd9\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"cbfcbaca2a1ceb2b056c48aad71d60f2dc7ea0a2","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule
Management","v8.13.0","v8.14.0"],"title":"fix: [Rules > Detection
rules][AXE-CORE]: Interactive controls must not be
nested","number":177710,"url":"https://github.com/elastic/kibana/pull/177710","mergeCommit":{"message":"fix:
[Rules > Detection rules][AXE-CORE]: Interactive controls must not be
nested (elastic#177710)\n\nCloses:
https://github.com/elastic/security-team/issues/8567\r\nCloses:
https://github.com/elastic/security-team/issues/8627\r\n\r\n##
Summary\r\n\r\nThe [axe browser plugin](https://deque.com/axe) is
reporting a nested\r\nbutton (interactive control). This appears to be a
tooltip nested within\r\na table sorting button. This pull request
addresses that issue in the\r\nsame manner as with
`EuiIconTip`.\r\n\r\nBy the way, I discovered a couple of accessibility
(a11y) issues in\r\nwhich also were fixed:\r\n- [x] Tooltip icon for
TableHeaderTooltipCell wasn't available for\r\nkeyboard navigation. It
was updated to use `EuiIconTip`.\r\n- [x] Set one color to \"subdued\"
for all tooltip icons.\r\n\r\n### Screens\r\n\r\n#### Axe report
\r\n\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/20072247/5bc57702-f63a-4c6c-9f9d-341a7ebaebc5\">\r\n\r\n\r\n####
Keyboard navigation
\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/20072247/8cd32a42-a711-42e4-ae11-badca4038fd9\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"cbfcbaca2a1ceb2b056c48aad71d60f2dc7ea0a2"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177710","number":177710,"mergeCommit":{"message":"fix:
[Rules > Detection rules][AXE-CORE]: Interactive controls must not be
nested (elastic#177710)\n\nCloses:
https://github.com/elastic/security-team/issues/8567\r\nCloses:
https://github.com/elastic/security-team/issues/8627\r\n\r\n##
Summary\r\n\r\nThe [axe browser plugin](https://deque.com/axe) is
reporting a nested\r\nbutton (interactive control). This appears to be a
tooltip nested within\r\na table sorting button. This pull request
addresses that issue in the\r\nsame manner as with
`EuiIconTip`.\r\n\r\nBy the way, I discovered a couple of accessibility
(a11y) issues in\r\nwhich also were fixed:\r\n- [x] Tooltip icon for
TableHeaderTooltipCell wasn't available for\r\nkeyboard navigation. It
was updated to use `EuiIconTip`.\r\n- [x] Set one color to \"subdued\"
for all tooltip icons.\r\n\r\n### Screens\r\n\r\n#### Axe report
\r\n\r\n<img width=\"1555\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/20072247/5bc57702-f63a-4c6c-9f9d-341a7ebaebc5\">\r\n\r\n\r\n####
Keyboard navigation
\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/20072247/8cd32a42-a711-42e4-ae11-badca4038fd9\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"cbfcbaca2a1ceb2b056c48aad71d60f2dc7ea0a2"}}]}]
BACKPORT-->

Co-authored-by: Alexey Antonov <[email protected]>
  • Loading branch information
kibanamachine and alexwizp authored Mar 7, 2024
1 parent 03636de commit 8f94eb0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,61 @@
* 2.0.
*/

import React, { useState } from 'react';
import { EuiPopover, EuiButtonIcon } from '@elastic/eui';
import React, { useState, useCallback } from 'react';
import type { EuiIconProps, IconColor } from '@elastic/eui';
import { EuiIcon, EuiPopover, keys } from '@elastic/eui';
import * as i18n from '../../../../detections/pages/detection_engine/rules/translations';

interface PopoverTooltipProps {
columnName: string;
children: React.ReactNode;
anchorColor?: IconColor;
}

/**
* Table column tooltip component utilizing EuiPopover for rich content like documentation links
* @param columnName string Name of column to use as aria-label of button
* @param children React.ReactNode of content to display in popover tooltip
*/
const PopoverTooltipComponent = ({ columnName, children }: PopoverTooltipProps) => {
const PopoverTooltipComponent = ({
columnName,
children,
anchorColor = 'primary',
}: PopoverTooltipProps) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const onClick: EuiIconProps['onClick'] = useCallback(
(event) => {
setIsPopoverOpen(!isPopoverOpen);
event.stopPropagation();
},
[isPopoverOpen]
);

const onKeyDown: EuiIconProps['onKeyDown'] = useCallback(
(event) => {
if (keys.ENTER === event.key) {
setIsPopoverOpen(!isPopoverOpen);
event.preventDefault();
event.stopPropagation();
}
},
[isPopoverOpen]
);

return (
<EuiPopover
anchorPosition={'upCenter'}
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
button={
<EuiButtonIcon
<EuiIcon
aria-label={i18n.POPOVER_TOOLTIP_ARIA_LABEL(columnName)}
onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
setIsPopoverOpen(!isPopoverOpen);
event.stopPropagation();
}}
size="xs"
color="primary"
iconType="questionInCircle"
style={{ height: 'auto' }}
tabIndex={0}
onClick={onClick}
onKeyDown={onKeyDown}
color={anchorColor}
type="questionInCircle"
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TableHeaderTooltipCell } from './table_header_tooltip_cell';
import { render, screen, fireEvent } from '@testing-library/react';

describe('Component TableHeaderTooltipCell', () => {
it('shoud render text with icon and tooltip', async () => {
it('should render text with icon and tooltip', async () => {
render(<TableHeaderTooltipCell title="test title" tooltipContent="test tooltip content" />);

expect(screen.getByText('test title')).toBeInTheDocument();
Expand All @@ -22,7 +22,7 @@ describe('Component TableHeaderTooltipCell', () => {
expect(await screen.findByText('test tooltip content')).toBeInTheDocument();
});

it('shoud render test element as custom tooltip', () => {
it('should render test element as custom tooltip', () => {
render(
<TableHeaderTooltipCell
title="test title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';

import { EuiToolTip, EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiIconTip, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

interface Props {
title: string;
Expand All @@ -28,15 +28,15 @@ const TableHeaderTooltipCellComponent = ({ title, tooltipContent, customTooltip
<span className="eui-textTruncate">{title}</span>
</EuiFlexItem>
{customTooltip ?? (
<EuiToolTip content={tooltipContent}>
<EuiIcon
data-test-subj="tableHeaderIcon"
size="m"
color="subdued"
type="questionInCircle"
style={{ marginLeft: 4 }}
/>
</EuiToolTip>
<EuiIconTip
content={tooltipContent}
type="questionInCircle"
color="subdued"
anchorProps={{
css: { marginLeft: 4 },
'data-test-subj': 'tableHeaderIcon',
}}
/>
)}
</EuiFlexGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,19 @@ export const useMonitoringColumns = ({
title={i18n.COLUMN_GAP}
customTooltip={
<div style={{ maxWidth: '20px' }}>
<PopoverTooltip columnName={i18n.COLUMN_GAP}>
<PopoverTooltip columnName={i18n.COLUMN_GAP} anchorColor="subdued">
<EuiText style={{ width: 300 }}>
<p>
<FormattedMessage
defaultMessage="Duration of most recent gap in Rule execution. Adjust Rule look-back or {seeDocs} for mitigating gaps."
id="xpack.securitySolution.detectionEngine.rules.allRules.columns.gapTooltip"
values={{
seeDocs: (
<EuiLink
href={`${docLinks.links.siem.troubleshootGaps}`}
target="_blank"
>
{i18n.COLUMN_GAP_TOOLTIP_SEE_DOCUMENTATION}
</EuiLink>
),
}}
/>
</p>
<FormattedMessage
defaultMessage="Duration of most recent gap in Rule execution. Adjust Rule look-back or {seeDocs} for mitigating gaps."
id="xpack.securitySolution.detectionEngine.rules.allRules.columns.gapTooltip"
values={{
seeDocs: (
<EuiLink href={`${docLinks.links.siem.troubleshootGaps}`} target="_blank">
{i18n.COLUMN_GAP_TOOLTIP_SEE_DOCUMENTATION}
</EuiLink>
),
}}
/>
</EuiText>
</PopoverTooltip>
</div>
Expand Down

0 comments on commit 8f94eb0

Please sign in to comment.