Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Timeline] Remove code added to workaround an eui issue, causing focus issues #158392

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { EuiFocusTrap, EuiOutsideClickDetector, EuiWindowEvent, keys } from '@elastic/eui';
import React, { useEffect, useMemo, useCallback, useState, useRef } from 'react';
import { EuiFocusTrap, EuiWindowEvent, keys } from '@elastic/eui';
import React, { useMemo, useCallback } from 'react';
import type { AppLeaveHandler } from '@kbn/core/public';
import { useDispatch } from 'react-redux';

Expand All @@ -24,8 +24,6 @@ interface OwnProps {
onAppLeave: (handler: AppLeaveHandler) => void;
}

type VoidFunc = () => void;

const FlyoutComponent: React.FC<OwnProps> = ({ timelineId, onAppLeave }) => {
const getTimelineShowStatus = useMemo(() => getTimelineShowStatusByIdSelector(), []);
const { show } = useDeepEqualSelector((state) => getTimelineShowStatus(state, timelineId));
Expand All @@ -36,31 +34,6 @@ const FlyoutComponent: React.FC<OwnProps> = ({ timelineId, onAppLeave }) => {
focusActiveTimelineButton();
}, [dispatch, timelineId]);

const [focusOwnership, setFocusOwnership] = useState(true);
const [triggerOnBlur, setTriggerOnBlur] = useState(true);
const callbackRef = useRef<VoidFunc | null>(null);
const searchRef = useRef<HTMLElement | null>(null);

const handleSearch = useCallback(() => {
if (show && focusOwnership === false) {
setFocusOwnership(true);
}
}, [show, focusOwnership]);

const onOutsideClick = useCallback((event) => {
setFocusOwnership(false);
const classes = event.target.classList;
if (classes.contains('kbnSearchBar')) {
searchRef.current = event.target;
setTriggerOnBlur((prev) => !prev);
window.setTimeout(() => {
if (searchRef.current !== null) {
searchRef.current.focus();
}
}, 0);
}
}, []);

// ESC key closes Pane
const onKeyDown = useCallback(
(ev: KeyboardEvent) => {
Expand All @@ -73,31 +46,14 @@ const FlyoutComponent: React.FC<OwnProps> = ({ timelineId, onAppLeave }) => {

useTimelineSavePrompt(timelineId, onAppLeave);

useEffect(() => {
if (searchRef.current != null) {
if (callbackRef.current !== null) {
searchRef.current.removeEventListener('blur', callbackRef.current);
}
searchRef.current.addEventListener('blur', handleSearch);
callbackRef.current = handleSearch;
}
return () => {
if (searchRef.current != null && callbackRef.current !== null) {
searchRef.current.removeEventListener('blur', callbackRef.current);
}
};
}, [handleSearch, triggerOnBlur]);

return (
<EuiOutsideClickDetector onOutsideClick={onOutsideClick}>
<>
<EuiFocusTrap disabled={!focusOwnership}>
<Pane timelineId={timelineId} visible={show} />
</EuiFocusTrap>
<FlyoutBottomBar showTimelineHeaderPanel={!show} timelineId={timelineId} />
<EuiWindowEvent event="keydown" handler={onKeyDown} />
</>
</EuiOutsideClickDetector>
<>
<EuiFocusTrap disabled={!show}>
<Pane timelineId={timelineId} visible={show} />
</EuiFocusTrap>
<FlyoutBottomBar showTimelineHeaderPanel={!show} timelineId={timelineId} />
<EuiWindowEvent event="keydown" handler={onKeyDown} />
</>
);
};

Expand Down