-
Notifications
You must be signed in to change notification settings - Fork 842
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
[EuiFocusTrap] Default to not trapping focus across iframes #6908
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
752c134
Upgrade `react-focus-on` to latest with `crossFrame` support
cee-chen 6f689b1
Add documentation
cee-chen 6e37fc9
changelog
cee-chen c7dc325
Add storybook for testing
cee-chen bd7655d
Upgrade to latest react-focus packages w/ various fixes
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,8 @@ | |
}, | ||
"resolutions": { | ||
"**/prismjs": "1.27.0", | ||
"**/react": "^17.0.0" | ||
"**/react": "^17.0.0", | ||
"react-focus-lock": "^2.9.5" | ||
}, | ||
"pre-commit": [ | ||
"test-staged" | ||
|
@@ -81,7 +82,7 @@ | |
"react-beautiful-dnd": "^13.1.0", | ||
"react-dropzone": "^11.5.3", | ||
"react-element-to-jsx-string": "^14.3.4", | ||
"react-focus-on": "^3.7.0", | ||
"react-focus-on": "^3.9.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"react-input-autosize": "^3.0.0", | ||
"react-is": "^17.0.2", | ||
"react-remove-scroll-bar": "^2.3.4", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { EuiButton } from '../button'; | ||
import { EuiFieldText } from '../form'; | ||
import { EuiSpacer } from '../spacer'; | ||
import { EuiPanel } from '../panel'; | ||
|
||
import { EuiFocusTrap, EuiFocusTrapProps } from './focus_trap'; | ||
|
||
const meta: Meta<EuiFocusTrapProps> = { | ||
title: 'EuiFocusTrap', | ||
// @ts-ignore This still works for Storybook controls, even though Typescript complains | ||
component: EuiFocusTrap, | ||
argTypes: { | ||
crossFrame: { | ||
control: { type: 'boolean' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<EuiFocusTrapProps>; | ||
|
||
const StatefulFocusTrap = (props: Partial<EuiFocusTrapProps>) => { | ||
const [disabled, setDisabled] = useState(props.disabled); | ||
return ( | ||
<> | ||
<EuiButton size="s" onClick={() => setDisabled(!disabled)}> | ||
Toggle focus trap | ||
</EuiButton> | ||
<EuiSpacer /> | ||
<EuiPanel> | ||
<EuiFocusTrap {...props} disabled={disabled}> | ||
Focus trap is currently {disabled ? 'disabled' : 'enabled'} | ||
<EuiFieldText /> | ||
<EuiButton size="s">Button inside focus trap</EuiButton> | ||
</EuiFocusTrap> | ||
</EuiPanel> | ||
</> | ||
); | ||
}; | ||
|
||
export const Playground: Story = { | ||
render: ({ ...args }) => <StatefulFocusTrap {...args} />, | ||
args: { | ||
disabled: true, | ||
}, | ||
}; | ||
|
||
export const Iframe: Story = { | ||
render: ({ ...args }) => ( | ||
<> | ||
<EuiFieldText placeholder="Focusable item outside iframe" /> | ||
<EuiSpacer /> | ||
<EuiPanel> | ||
Iframe content | ||
<iframe | ||
title="crossFrame test" | ||
src={`/iframe.html?id=euifocustrap--playground&crossFrame=${args.crossFrame}`} | ||
style={{ width: '100%', height: 200 }} | ||
sandbox="allow-forms allow-modals allow-popups allow-same-origin allow-scripts allow-downloads allow-storage-access-by-user-activation" | ||
/> | ||
</EuiPanel> | ||
</> | ||
), | ||
args: { disabled: true, crossFrame: false }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- `EuiFocusTrap` now supports configuring cross-iframe focus trapping via the `crossFrame` prop | ||
|
||
**Breaking changes** | ||
|
||
- `EuiFocusTrap` now defaults to *not* trapping focus across iframes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This resolution is necessary as latest
react-focus-on
still points to2.9.4
which doesn't yet have thereact-focus-lock
fix we need (theKashey/react-focus-lock#249). Oncereact-focus-on
updates, we can remove this resolution