Skip to content

Commit

Permalink
Merge pull request #11 from wayfair-incubator/vpodk-is-enabled
Browse files Browse the repository at this point in the history
Added isEnabled prop, updated README
  • Loading branch information
vpodk authored Nov 9, 2021
2 parents 77a3f78 + 3ecf220 commit 2475ac5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ Be sure you use latest stable version of `npm`:
npm install npm@latest -g
```

### Installation

Clone the repo

```sh
git clone https://github.com/wayfair-incubator/react-focus-bounder.git
```

Install NPM packages

```sh
npm install
```

## Usage

```bash
Expand All @@ -69,6 +55,7 @@ import FocusBounder from 'react-focus-bounder';

- `firstElementIndex` - An optional index of the first focusable element. Default `0`.
- `focusTimeoutDelay` - An optional timeout to wait for the element to be fully visible. Default `0`.
- `isEnabled` - An optional property to enable or disable this component functionality. Default `true`.

## Roadmap

Expand Down
7 changes: 5 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type FocusBounderProps = {
children: React.ReactNode;
firstElementIndex?: number;
focusTimeoutDelay?: number;
isEnabled?: boolean;
};

/**
Expand All @@ -30,11 +31,13 @@ type FocusBounderProps = {
* @param {!React.ReactNode} props.children Child nodes to be wrapped.
* @param {number=} props.firstElementIndex An optional index of the first focusable element.
* @param {number=} props.focusTimeoutDelay An optional timeout to wait for the element to be fully visible.
* @param {boolean=} props.isEnabled An optional property to enable or disable this component functionality.
*/
const FocusBounder = ({
children,
firstElementIndex = 0,
focusTimeoutDelay = 0,
isEnabled = true,
}: FocusBounderProps) => {
/**
* A reference to the first of the two bounding elements.
Expand All @@ -50,7 +53,7 @@ const FocusBounder = ({
*/
const setFocus = useCallback(
(index: number) => {
if (focusBounder.current) {
if (isEnabled && focusBounder.current) {
// Getting the container element containing bounders.
const container = focusBounder.current.parentNode;
// Getting all focusable elements in the boudered container.
Expand All @@ -70,7 +73,7 @@ const FocusBounder = ({
}
}
},
[focusBounder, focusTimeoutDelay]
[isEnabled, focusBounder, focusTimeoutDelay]
);

/**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-focus-bounder",
"version": "1.0.0",
"version": "1.1.0",
"description": "Focus looping component based on focus bounders.",
"homepage": "https://github.com/wayfair-incubator/react-focus-bounder",
"repository": "github:wayfair-incubator/react-focus-bounder",
Expand Down

0 comments on commit 2475ac5

Please sign in to comment.