Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

[RFC] feat(Accessibility): Add focus trap zone #239

Merged
merged 95 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
faa40f4
Add @uifabric/utilities
tomasiser Aug 17, 2018
41f022d
customPropTypes fix for @types
tomasiser Aug 20, 2018
b486711
FocusZone in renderComponent
tomasiser Aug 20, 2018
d445a4c
Fixed handlesAccessibility unit test for FocusZone wrap
tomasiser Aug 21, 2018
4889064
Fixed isConformant.tsx unit tests for FocusZone
tomasiser Aug 21, 2018
ff124af
Merge branch 'master' of https://github.com/stardust-ui/react into fe…
tomasiser Aug 22, 2018
9356364
Removed debug logging, added circular navigation to menu
tomasiser Aug 22, 2018
3d63a14
Fix menu props and add constant
tomasiser Aug 22, 2018
e9f1cf1
FocusZone unit tests
tomasiser Aug 22, 2018
518e3f8
Improved typing of a function
tomasiser Aug 24, 2018
59a05af
Merge remote-tracking branch 'origin/master' into feat/acc-focuszone-…
tomasiser Aug 24, 2018
d4f3a21
Merged latest FocusZone RTL fix and added CHANGELOG.md
tomasiser Aug 27, 2018
d30e2ae
Merge remote-tracking branch 'origin/master' into feat/acc-focuszone-…
tomasiser Aug 27, 2018
9ae3071
Merge branch 'master' into feat/acc-focuszone-in-rendercomponent
sophieH29 Aug 28, 2018
b8bc7da
Got rid of Fabric utilities dependency
tomasiser Aug 28, 2018
e073afe
More cleanup
tomasiser Aug 29, 2018
a07c290
Added PropTypes, fixed unit tests
tomasiser Aug 29, 2018
f3e0f19
Renamed props and refactored unit tests
tomasiser Aug 29, 2018
0e6825d
Typo in test
tomasiser Aug 29, 2018
772df90
Temporary fix for customPropTypes.as not working
tomasiser Aug 29, 2018
441c135
Updated FocusZone CHANGELOG
tomasiser Aug 29, 2018
0e01d04
Merge branch 'feat/acc-focuszone-in-rendercomponent' of https://githu…
tomasiser Aug 29, 2018
10f7aff
Strict type
tomasiser Aug 30, 2018
25092d4
Merge remote-tracking branch 'origin/master' into feat/acc-focuszone-…
tomasiser Aug 30, 2018
1676c56
Added isRtl, moved constants
tomasiser Aug 30, 2018
50bda74
feat(portal): simple base implementation
bmdalex Aug 23, 2018
d0df7ed
addressed PR comments
bmdalex Aug 28, 2018
f89f9ec
feat(popup): simple base implementation
bmdalex Aug 23, 2018
01710c7
Merge branch 'master' of https://github.com/stardust-ui/react into fe…
bmdalex Sep 7, 2018
7b9e89e
addressed comments
bmdalex Sep 7, 2018
a1da665
addressed comments
bmdalex Sep 7, 2018
0b800d0
Merge branch 'feat/popup-simple' of https://github.com/stardust-ui/re…
bmdalex Sep 10, 2018
f25dd64
addressed comments
bmdalex Sep 10, 2018
cab3a3a
Add accessibility PopupBehavior, make improvements to Popup and Portal
Sep 10, 2018
03fd813
Merge latest changes from popup-simple into current branch
Sep 10, 2018
8233bf0
addressed comments
bmdalex Sep 10, 2018
2ec0fae
Merge branch 'master' of https://github.com/stardust-ui/react into fe…
bmdalex Sep 11, 2018
ce91227
fixed unit tests
bmdalex Sep 11, 2018
cc3fdb0
Merge remote-tracking branch 'origin/master' into feat/acc-focuszone-…
tomasiser Sep 11, 2018
c57ec99
Merge branch 'feat/popup-simple' into feat/acc-popup
Sep 11, 2018
a129632
Made improvement
Sep 11, 2018
9e3a04f
Made improvement
Sep 11, 2018
37a117a
Made improvement
Sep 11, 2018
d1c1831
Fixed FocusZone return values
tomasiser Sep 11, 2018
6a5c40d
Merge focus-zone
Sep 11, 2018
3f361b7
Manage focus after open / close popup
Sep 11, 2018
ed4873b
Add focus Trap zone
Sep 12, 2018
6d97381
Add FocusTrapZone - WIP
Sep 13, 2018
e5949ec
Add FocusTrapZone - WIP
Sep 13, 2018
faa1eec
Add FocusTrapZone - minor improvement
Sep 17, 2018
003764f
Merge branch 'master' into feat/focus-trap-zone
Sep 17, 2018
f7afecc
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 18, 2018
f31b638
Add unit tests for FocusTrapZone
Sep 18, 2018
2ba0c83
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 18, 2018
dd23c3c
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 20, 2018
e05ae05
Fix example
Sep 20, 2018
a5bcf13
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 20, 2018
74ec6b5
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 21, 2018
b56474b
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 21, 2018
2f9ff67
Updates after CR comments
Sep 21, 2018
a2fa2f2
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 24, 2018
7498f2c
Fix for tests
Sep 24, 2018
26b0aea
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Sep 24, 2018
9f6cfd6
Remove redundant space
sophieH29 Oct 1, 2018
894c073
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 1, 2018
ec64fce
Remove handledProps
Oct 1, 2018
a1b8366
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 2, 2018
57ed84b
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 2, 2018
cf6296b
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 3, 2018
550877a
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 3, 2018
fa89260
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 4, 2018
1e8e508
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 4, 2018
86ef8e3
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 5, 2018
b9b8183
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 8, 2018
5b9f987
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 9, 2018
3f810f3
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 10, 2018
4adc136
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 10, 2018
b691f6a
Merge branch 'master' into feat/focus-trap-zone
alinais Oct 11, 2018
20e4ce6
Merge branch 'master' into feat/focus-trap-zone
jurokapsiar Oct 11, 2018
18f40b9
add FocusTrapZone information to FocusZone CHANGELOG.md
Oct 11, 2018
63d66c4
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 16, 2018
68b9137
Make improvements after CR comments
Oct 17, 2018
90307e3
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 19, 2018
3737ffb
Make improvements after CR comments
Oct 22, 2018
7a3c913
Merge branch 'feat/focus-trap-zone' of https://github.com/stardust-ui…
Oct 22, 2018
5d0b138
Merge latest master into current branch
Oct 22, 2018
d7a0e6d
Improvements after CR, update styled for Portal examples
Oct 22, 2018
08497bc
small improvement
Oct 22, 2018
980935e
Improvements after CR
Oct 22, 2018
86e186b
Update changelog
Oct 22, 2018
27bc75a
Merge branch 'master' into feat/focus-trap-zone
Oct 22, 2018
9bffdf7
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 22, 2018
6443f0a
Merge branch 'master' into feat/focus-trap-zone
sophieH29 Oct 23, 2018
ad58d48
Rename IFocusTrapZoneProps -> FocusTrapZoneProps
Oct 23, 2018
0472f3b
Improve descriptions
Oct 23, 2018
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 @@ -18,6 +18,7 @@ class PortalExamplePortal extends React.Component {
return (
<div>
<Portal
trapFocus={true}
content={
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react'
import { Button, Header, Portal } from '@stardust-ui/react'

class PortalExampleFocusTrapped extends React.Component {
state = { open: false }

openPortal = () => {
this.setState({ open: true })
}

closePortal = () => {
this.setState({ open: false })
}

render() {
const { open } = this.state
const btnContent = open ? 'Close Portal' : 'Open Portal'

return (
<div>
<Button content={btnContent} onClick={this.openPortal} />
<Portal
trapFocus={true}
focusTrapZoneProps={{
isClickableOutsideFocusTrap: false,
}}
open={open}
content={
<div
style={{
background: '#ddd',
position: 'fixed',
left: '40%',
top: '45%',
zIndex: 1000,
padding: '10px',
}}
>
<Header>This is a portal with focus trap!</Header>
<p tabIndex={0}>Portals have tons of great callback functions to hook into.</p>
<p tabIndex={0}>To close, simply click the close button or click away</p>
<Button size="small" content="Do nothing" />
<Button size="small" content="Close popup" onClick={this.closePortal} />
</div>
}
/>
</div>
)
}
}

export default PortalExampleFocusTrapped
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react'
import { Button, Header, Portal } from '@stardust-ui/react'

class PortalExamplePortal extends React.Component {
state = { open: false }

openPortal = () => {
this.setState({ open: true })
}

closePortal = () => {
this.setState({ open: false })
}

render() {
const { open } = this.state
const btnContent = open ? 'Close Portal' : 'Open Portal'

return (
<div>
<Button content={btnContent} onClick={this.openPortal} />
<Portal
open={open}
trapFocus={true}
focusTrapZoneProps={{
isClickableOutsideFocusTrap: false,
}}
>
<div
style={{
background: '#ddd',
position: 'fixed',
left: '40%',
top: '45%',
zIndex: 1000,
padding: '10px',
}}
>
<Header>This is a portal with focus trap!</Header>
sophieH29 marked this conversation as resolved.
Show resolved Hide resolved
<p tabIndex={0}>Portals have tons of great callback functions to hook into.</p>
<p tabIndex={0}>To close, simply click the close button or click away</p>
sophieH29 marked this conversation as resolved.
Show resolved Hide resolved
<Button size="small" content="Do nothing" />
<Button size="small" content="Close popup" onClick={this.closePortal} />
</div>
</Portal>
</div>
)
}
}

export default PortalExamplePortal
5 changes: 5 additions & 0 deletions docs/src/examples/components/Portal/Types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const PortalTypesExamples = () => (
description="A controlled portal."
examplePath="components/Portal/Types/PortalExampleControlled"
/>
<ComponentExample
title="With Focus Trap"
description="A portal with a focus trap."
examplePath="components/Portal/Types/PortalExampleFocusTrapped"
/>
</ExampleSection>
)

Expand Down
21 changes: 18 additions & 3 deletions src/components/Portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { ItemShorthand, ReactChildren } from '../../../types/utils'
import Ref from '../Ref'
import PortalInner from './PortalInner'
import { FocusTrapZone, IFocusTrapZoneProps } from '../../lib/accessibility/FocusZone'

type ReactMouseEvent = React.MouseEvent<HTMLElement>

Expand All @@ -23,7 +24,8 @@ export interface IPortalProps {
onUnmount?: (props: IPortalProps) => void
open?: boolean
trigger?: JSX.Element
triggerRef?: (node: HTMLElement) => void
trapFocus?: boolean
focusTrapZoneProps?: IFocusTrapZoneProps
jurokapsiar marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IPortalState {
Expand Down Expand Up @@ -75,15 +77,23 @@ class Portal extends AutoControlledComponent<IPortalProps, IPortalState> {
* @param {JSX.Element} node - Referred node.
*/
triggerRef: PropTypes.func,

/** Controls whether or not focus trap should be applied */
trapFocus: PropTypes.bool,

/** FocusTrapZone props */
focusTrapZoneProps: PropTypes.object,
}

public static handledProps = [
'children',
'content',
'defaultOpen',
'focusTrapZoneProps',
'onMount',
'onUnmount',
'open',
'trapFocus',
'trigger',
'triggerRef',
]
Expand All @@ -98,14 +108,19 @@ class Portal extends AutoControlledComponent<IPortalProps, IPortalState> {
}

private renderPortal(): JSX.Element | undefined {
const { children, content } = this.props
const { children, content, trapFocus, focusTrapZoneProps } = this.props
const { open } = this.state
const contentToRender = childrenExist(children) ? children : content

return (
open && (
<Ref innerRef={this.handlePortalRef}>
<PortalInner onMount={this.handleMount} onUnmount={this.handleUnmount}>
{childrenExist(children) ? children : content}
{trapFocus ? (
<FocusTrapZone {...focusTrapZoneProps}>{contentToRender}</FocusTrapZone>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

) : (
contentToRender
)}
</PortalInner>
</Ref>
)
Expand Down
Loading