Skip to content

Commit

Permalink
fix: update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jun 16, 2020
1 parent 26b2e92 commit 7f977fb
Show file tree
Hide file tree
Showing 8 changed files with 4,698 additions and 6,240 deletions.
36 changes: 18 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

### Bug Fixes

* correct behavior for radio buttons at the edge of lock, fixes [#103](https://github.com/theKashey/react-focus-lock/issues/103) ([9dac851](https://github.com/theKashey/react-focus-lock/commit/9dac851))
* correct behavior for radio buttons at the edge of lock, fixes [#103](https://github.com/theKashey/react-focus-lock/issues/103) ([9dac851](https://github.com/theKashey/react-focus-lock/commit/9dac85167508ed3e761545ffcc877ef891013d2c))


### Features

* add crossFrame property to control iframe behaviour, fixes [#104](https://github.com/theKashey/react-focus-lock/issues/104) ([486a7e0](https://github.com/theKashey/react-focus-lock/commit/486a7e0))
* add crossFrame property to control iframe behaviour, fixes [#104](https://github.com/theKashey/react-focus-lock/issues/104) ([486a7e0](https://github.com/theKashey/react-focus-lock/commit/486a7e08428487286d09ef7bfeaa701e8376318d))



Expand All @@ -25,7 +25,7 @@

### Features

* use forwardRef, and allow custom as prop ([af0e560](https://github.com/theKashey/react-focus-lock/commit/af0e560))
* use forwardRef, and allow custom as prop ([af0e560](https://github.com/theKashey/react-focus-lock/commit/af0e560966ce3dd936d6fb7f3665ecab972bdd20))



Expand All @@ -50,7 +50,7 @@

### Bug Fixes

* onActivation hooks not called in v2 ([ee1cb14](https://github.com/theKashey/react-focus-lock/commit/ee1cb14))
* onActivation hooks not called in v2 ([ee1cb14](https://github.com/theKashey/react-focus-lock/commit/ee1cb14b8cd3c28f5ce8e093f1b7aa95779f3563))



Expand All @@ -63,14 +63,14 @@

### Bug Fixes

* nested return focus, fixes [#68](https://github.com/theKashey/react-focus-lock/issues/68) ([df4b313](https://github.com/theKashey/react-focus-lock/commit/df4b313))
* useLayoutEffect for focus actions ([254e2ae](https://github.com/theKashey/react-focus-lock/commit/254e2ae))
* nested return focus, fixes [#68](https://github.com/theKashey/react-focus-lock/issues/68) ([df4b313](https://github.com/theKashey/react-focus-lock/commit/df4b31389494a3dc7a3ebe5ce928721b1c289490))
* useLayoutEffect for focus actions ([254e2ae](https://github.com/theKashey/react-focus-lock/commit/254e2aee9433da048704dda159582fcb90b7f4c1))


### Features

* sidecar code splitting pattern ([187c3c8](https://github.com/theKashey/react-focus-lock/commit/187c3c8))
* sidecar FocusLock ([5493986](https://github.com/theKashey/react-focus-lock/commit/5493986))
* sidecar code splitting pattern ([187c3c8](https://github.com/theKashey/react-focus-lock/commit/187c3c8adc3d5613a7a3092398e024b78e545d02))
* sidecar FocusLock ([5493986](https://github.com/theKashey/react-focus-lock/commit/5493986ccb49b3f3a189a8859c478fbb7089d520))



Expand All @@ -83,12 +83,12 @@

### Bug Fixes

* infinite loop on ref set ([29e9691](https://github.com/theKashey/react-focus-lock/commit/29e9691))
* infinite loop on ref set ([29e9691](https://github.com/theKashey/react-focus-lock/commit/29e9691fb516a92e99322a9832ceb120bb2e475e))


### Features

* no tail guard ([c0c5fde](https://github.com/theKashey/react-focus-lock/commit/c0c5fde))
* no tail guard ([c0c5fde](https://github.com/theKashey/react-focus-lock/commit/c0c5fde64d6d07414ab5a57c807dc8ac6bdb2ac3))



Expand All @@ -97,7 +97,7 @@

### Bug Fixes

* simplify proptype for shards, fixes [#59](https://github.com/theKashey/react-focus-lock/issues/59) ([55b7129](https://github.com/theKashey/react-focus-lock/commit/55b7129))
* simplify proptype for shards, fixes [#59](https://github.com/theKashey/react-focus-lock/issues/59) ([55b7129](https://github.com/theKashey/react-focus-lock/commit/55b7129eb117aaf66c0c835d89deb74c27d59446))



Expand All @@ -106,7 +106,7 @@

### Bug Fixes

* use only auto guards ([12dab4a](https://github.com/theKashey/react-focus-lock/commit/12dab4a))
* use only auto guards ([12dab4a](https://github.com/theKashey/react-focus-lock/commit/12dab4a636b96a12fc19f4ad4574d4498c25407a))



Expand All @@ -115,7 +115,7 @@

### Bug Fixes

* support old refs ([8b87c2f](https://github.com/theKashey/react-focus-lock/commit/8b87c2f))
* support old refs ([8b87c2f](https://github.com/theKashey/react-focus-lock/commit/8b87c2f938e5dba4b303625068b9eaafe858d51b))



Expand All @@ -124,7 +124,7 @@

### Features

* introduce shards ([7bc46f0](https://github.com/theKashey/react-focus-lock/commit/7bc46f0))
* introduce shards ([7bc46f0](https://github.com/theKashey/react-focus-lock/commit/7bc46f0f81255455238999f56bf001c5c83797ea))



Expand All @@ -133,7 +133,7 @@

### Bug Fixes

* nested portals ([9878ba7](https://github.com/theKashey/react-focus-lock/commit/9878ba7))
* nested portals ([9878ba7](https://github.com/theKashey/react-focus-lock/commit/9878ba72550272c7638781db7b923bf4c138bf4e))



Expand All @@ -146,7 +146,7 @@

### Bug Fixes

* initially disabled buttons with tabindex set, [#50](https://github.com/theKashey/react-focus-lock/issues/50) ([12e33e5](https://github.com/theKashey/react-focus-lock/commit/12e33e5))
* initially disabled buttons with tabindex set, [#50](https://github.com/theKashey/react-focus-lock/issues/50) ([12e33e5](https://github.com/theKashey/react-focus-lock/commit/12e33e5e3d721d48045d7f8ba40d68cdd04db866))



Expand Down Expand Up @@ -195,7 +195,7 @@

### Features

* add 'as' and 'lockProps', [#44](https://github.com/theKashey/react-focus-lock/issues/44) ([5274e24](https://github.com/theKashey/react-focus-lock/commit/5274e24))
* add 'as' and 'lockProps', [#44](https://github.com/theKashey/react-focus-lock/issues/44) ([5274e24](https://github.com/theKashey/react-focus-lock/commit/5274e2433a471c70640675a72a8285d563aaba88))



Expand Down Expand Up @@ -228,7 +228,7 @@

### Bug Fixes

* Safary and Negative TabIndex, [#33](https://github.com/theKashey/react-focus-lock/issues/33) ([f4a6a6d](https://github.com/theKashey/react-focus-lock/commit/f4a6a6d))
* Safary and Negative TabIndex, [#33](https://github.com/theKashey/react-focus-lock/issues/33) ([f4a6a6d](https://github.com/theKashey/react-focus-lock/commit/f4a6a6d2aaf3b52deaa376f497b6a329f9b2a7e3))



Expand Down
7 changes: 6 additions & 1 deletion UI/UI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ export class FreeFocusInside extends React.Component<FreeFocusProps> {
* Secures the focus around the node
*/
export class InFocusGuard extends React.Component<InFocusGuardProps> {
}
}

/**
* Moves focus inside a given node
*/
export function useFocusInside(node: React.RefObject<HTMLElement>):void;
8 changes: 7 additions & 1 deletion _tests/FocusLock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ describe('react-focus-lock', () => {
});

afterEach(() => {
mountPoint.forEach(wrapper => wrapper.unmount());
mountPoint.forEach(wrapper => {
try {
wrapper.unmount()
} catch (e){

}
});
document.body.focus();
});

Expand Down
1 change: 1 addition & 0 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface ReactFocusLockProps<ChildrenType = React.ReactNode, LockProps=R

export interface AutoFocusProps {
children: React.ReactNode;
disabled?: boolean;
className?: string;
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"chai-enzyme": "^1.0.0-beta.0",
"conventional-changelog-cli": "^2.0.12",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.7.1",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.17.3",
Expand All @@ -85,7 +85,6 @@
"mocha": "^6.1.4",
"package-self": "^1.1.1",
"react": "^16.8.6",
"react-compat": "^0.0.1",
"react-dom": "^16.8.6",
"react-hot-loader": "^4.11.0",
"react-test-renderer": "^16.2.0",
Expand Down
24 changes: 13 additions & 11 deletions src/MoveFocusInside.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@ import * as constants from 'focus-lock/constants';
import { inlineProp } from './util';
import { mediumEffect } from './medium';

function MoveFocusInside({ disabled: isDisabled, className, children }) {
const ref = React.useRef(null);
const disabled = React.useRef(isDisabled);
const moveFocus = () => {
const observed = ref.current;
export const useFocusInside = (observedRef) => {
React.useEffect(() => {
let enabled = true;
mediumEffect.useMedium((car) => {
if (!disabled.current && observed) {
const observed = observedRef && observedRef.current;
if (enabled && observed) {
if (!car.focusInside(observed)) {
car.moveFocusInside(observed, null);
}
}
});
};
return () => {
enabled = false;
};
}, [observedRef]);
};

React.useEffect(() => {
disabled.current = isDisabled;
moveFocus();
}, [isDisabled]);
function MoveFocusInside({ disabled: isDisabled, className, children }) {
const ref = React.useRef(null);
useFocusInside(isDisabled ? undefined : ref);

return (
<div
Expand Down
4 changes: 3 additions & 1 deletion src/UI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FocusLockUI from './Lock';
import AutoFocusInside from './AutoFocusInside';
import MoveFocusInside from './MoveFocusInside';
import MoveFocusInside, { useFocusInside } from './MoveFocusInside';
import FreeFocusInside from './FreeFocusInside';
import InFocusGuard from './FocusGuard';

Expand All @@ -10,6 +10,8 @@ export {
FreeFocusInside,
InFocusGuard,
FocusLockUI,

useFocusInside,
};

export default FocusLockUI;
Loading

0 comments on commit 7f977fb

Please sign in to comment.