Skip to content

Commit

Permalink
update newsfeed flyout to use shards
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed May 4, 2022
1 parent 25fd304 commit 7645d35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/plugins/newsfeed/public/components/flyout_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutHeader,
EuiFlyoutProps,
EuiTitle,
EuiLink,
EuiFlyoutFooter,
Expand All @@ -28,13 +29,14 @@ import { NewsfeedItem } from '../types';
import { NewsEmptyPrompt } from './empty_news';
import { NewsLoadingPrompt } from './loading_news';

export const NewsfeedFlyout = () => {
export const NewsfeedFlyout = (props: Partial<EuiFlyoutProps>) => {
const { newsFetchResult, setFlyoutVisible } = useContext(NewsfeedContext);
const closeFlyout = useCallback(() => setFlyoutVisible(false), [setFlyoutVisible]);

return (
<EuiPortal>
<EuiFlyout
{...props}
onClose={closeFlyout}
size="s"
aria-labelledby="flyoutSmallTitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useState, useEffect, useMemo, useCallback } from 'react';
import React, { useState, useEffect, useMemo, useCallback, useRef } from 'react';
import { EuiHeaderSectionItemButton, EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { NewsfeedApi } from '../lib/api';
Expand All @@ -31,6 +31,9 @@ export const NewsfeedNavButton = ({ newsfeedApi }: Props) => {
return newsFetchResult ? newsFetchResult.hasNew : false;
}, [newsFetchResult]);

const buttonRef = useRef<HTMLButtonElement | null>(null);
const setButtonRef = (node: HTMLButtonElement | null) => (buttonRef.current = node);

useEffect(() => {
const subscription = newsfeedApi.fetchResults$.subscribe((results) => {
setNewsFetchResult(results);
Expand All @@ -49,6 +52,7 @@ export const NewsfeedNavButton = ({ newsfeedApi }: Props) => {
<NewsfeedContext.Provider value={{ setFlyoutVisible, newsFetchResult }}>
<>
<EuiHeaderSectionItemButton
ref={setButtonRef}
data-test-subj="newsfeed"
aria-controls="keyPadMenu"
aria-expanded={flyoutVisible}
Expand All @@ -67,7 +71,7 @@ export const NewsfeedNavButton = ({ newsfeedApi }: Props) => {
>
<EuiIcon type="cheer" size="m" />
</EuiHeaderSectionItemButton>
{flyoutVisible ? <NewsfeedFlyout /> : null}
{flyoutVisible ? <NewsfeedFlyout focusTrapProps={{ shards: [buttonRef] }} /> : null}
</>
</NewsfeedContext.Provider>
);
Expand Down

0 comments on commit 7645d35

Please sign in to comment.