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

[EuiPopover][EuiInputPopover] Allow more control via focusTrapProps #6955

Merged
merged 4 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/components/popover/input_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const EuiInputPopover: FunctionComponent<EuiInputPopoverProps> = ({
children,
className,
disableFocusTrap = false,
focusTrapProps,
input,
fullWidth = false,
onPanelResize,
Expand Down Expand Up @@ -123,7 +124,11 @@ export const EuiInputPopover: FunctionComponent<EuiInputPopoverProps> = ({
className={classes}
{...props}
>
<EuiFocusTrap clickOutsideDisables={true} disabled={disableFocusTrap}>
<EuiFocusTrap
clickOutsideDisables={true}
disabled={disableFocusTrap}
{...focusTrapProps}
>
<div onKeyDown={onKeyDown}>{children}</div>
</EuiFocusTrap>
</EuiPopover>
Expand Down
18 changes: 2 additions & 16 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { focusable } from 'tabbable';

import { CommonProps, NoArgCallback } from '../common';
import { FocusTarget, EuiFocusTrap, EuiFocusTrapProps } from '../focus_trap';
import { ReactFocusOnProps } from 'react-focus-on/dist/es5/types';

import {
cascadingMenuKeys,
Expand Down Expand Up @@ -103,14 +102,7 @@ export interface EuiPopoverProps extends CommonProps {
/**
* Object of props passed to EuiFocusTrap
*/
focusTrapProps?: Pick<
EuiFocusTrapProps,
| 'clickOutsideDisables'
| 'onClickOutside'
| 'noIsolation'
| 'scrollLock'
| 'shards'
>;
focusTrapProps?: Partial<EuiFocusTrapProps>;
/**
* Show arrow indicating to originating button
*/
Expand Down Expand Up @@ -181,10 +173,6 @@ export interface EuiPopoverProps extends CommonProps {
* component; pass `zIndex` to override
*/
zIndex?: number;
/**
* Function callback for when the focus trap is deactivated
*/
onTrapDeactivation?: ReactFocusOnProps['onDeactivation'];
/**
* Distance away from the anchor that the popover will render
*/
Expand Down Expand Up @@ -627,7 +615,6 @@ export class EuiPopover extends Component<Props, State> {
display,
offset,
onPositionChange,
onTrapDeactivation,
buffer,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
Expand Down Expand Up @@ -703,14 +690,13 @@ export class EuiPopover extends Component<Props, State> {
<EuiFocusTrap
clickOutsideDisables={true}
onClickOutside={this.onClickOutside}
{...focusTrapProps}
returnFocus={returnFocus} // Ignore temporary state of indecisive focus
initialFocus={initialFocus}
onDeactivation={onTrapDeactivation}
onEscapeKey={this.onEscapeKey}
disabled={
!ownFocus || !this.state.isOpenStable || this.state.isClosing
}
{...focusTrapProps}
>
<EuiPopoverPanel
{...(panelProps as EuiPopoverPanelProps)}
Expand Down
10 changes: 10 additions & 0 deletions upcoming_changelogs/6955.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- Updated `EuiPopover` to allow consumer control of all `focusTrapProps`

**Bug fixes**

- Fixed `EuiInputPopover` to allow consumer control of its focus trap via `focusTrapProps`

**Breaking changes**

- Removed `onTrapDeactivation` prop from `EuiPopover`. Use `focusTrapProps.onDeactivation` instead