-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
16 deletions.
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import * as React from "react"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
danielweck
|
||
|
||
declare module 'react-focus-lock' { | ||
import * as React from 'react'; | ||
|
||
|
@@ -40,16 +42,22 @@ declare module 'react-focus-lock' { | |
*/ | ||
group?: string; | ||
|
||
children: React.ReactNode; | ||
|
||
className?: string; | ||
|
||
/** | ||
* Component to use, defaults to 'div' | ||
*/ | ||
as?: React.ReactType, | ||
lockProps?: { [key:string]: any }, | ||
|
||
/** | ||
* Controls focus lock working areas. Lock will silently ignore all the events from `not allowed` areas | ||
* @param activeElement | ||
* @returns {Boolean} true if focus lock should handle activeElement, false if not | ||
*/ | ||
whiteList?: (activeElement: HTMLElement) => boolean; | ||
|
||
children: React.ReactNode; | ||
} | ||
|
||
interface AutoFocusProps { | ||
|
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,84 @@ | ||
import React, {Component} from "react"; | ||
import FocusLock from "../src/index"; | ||
|
||
export class StyledSection extends Component { | ||
state = { | ||
disabled: true | ||
} | ||
|
||
toggle = () => this.setState({disabled: !this.state.disabled}); | ||
|
||
render() { | ||
const {disabled} = this.state; | ||
return ( | ||
<div> | ||
should be a styled section | ||
{disabled && <div> | ||
! this is a <b>real trap</b>.<br/> | ||
We will steal your focus ! <br/><br/> | ||
<button onClick={this.toggle}>!ACTIVATE THE TRAP!</button> | ||
<br/> | ||
<br/> | ||
</div> | ||
} | ||
<FocusLock disabled={this.state.disabled} as="section" lockProps={{style:{border:"1px solid red"}}}> | ||
<button>BUTTON</button> | ||
<button data-autofocus>Will be autofocused</button> | ||
<button>BUTTON</button> | ||
<br/> | ||
|
||
<a href='#'>link somethere</a> <br/> | ||
|
||
{ | ||
!disabled && <div> | ||
<button onClick={this.toggle}>DEACTIVATE</button> | ||
<br/> | ||
</div> | ||
} | ||
</FocusLock> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const Comp = (props) => <main {...props} data-focus-locked-test/>; | ||
|
||
export class StyledComponent extends Component { | ||
state = { | ||
disabled: true | ||
} | ||
|
||
toggle = () => this.setState({disabled: !this.state.disabled}); | ||
|
||
render() { | ||
const {disabled} = this.state; | ||
return ( | ||
<div> | ||
should be a styled section | ||
{disabled && <div> | ||
! this is a <b>real trap</b>.<br/> | ||
We will steal your focus ! <br/><br/> | ||
<button onClick={this.toggle}>!ACTIVATE THE TRAP!</button> | ||
<br/> | ||
<br/> | ||
</div> | ||
} | ||
<FocusLock disabled={this.state.disabled} as={Comp} lockProps={{style: {border: "1px solid red"}}}> | ||
<button>BUTTON</button> | ||
<button data-autofocus>Will be autofocused</button> | ||
<button>BUTTON</button> | ||
<br/> | ||
|
||
<a href='#'>link somethere</a> <br/> | ||
|
||
{ | ||
!disabled && <div> | ||
<button onClick={this.toggle}>DEACTIVATE</button> | ||
<br/> | ||
</div> | ||
} | ||
</FocusLock> | ||
</div> | ||
) | ||
} | ||
} |
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
Isn't that redundant with line 4?
Also, with TypeScript 3 I get the following error regarding line 4, so perhaps it would be best to only preserve line 1?
TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.