Skip to content

Update node version in .nvmrc #87

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

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,12 +1,13 @@
name: Test
name: Test PR

on:
pull_request:
branches: [main]
paths:
- 'src/**'
- '__tests__/**'
- yarn.lock
- package-lock.json
- .nvmrc

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -20,7 +21,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn run coverage
- run: yarn run build
cache: 'npm'
- run: npm ci --legacy-peer-deps
- run: npm run coverage
- run: npm run build
6 changes: 3 additions & 3 deletions .github/workflows/publish-on-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [main, beta]
paths:
- 'src/**'
- yarn.lock
- package-lock.json

jobs:
release:
Expand All @@ -15,8 +15,8 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn install --frozen-lockfile
cache: 'npm'
- run: npm ci --legacy-peer-deps
- run: npx semantic-release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/report-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
branches: [main]
paths:
- 'src/**'
- '__tests__/**'
- 'src/**'
- '__tests__/**'

jobs:
report_test_coverage:
Expand All @@ -15,9 +15,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn run coverage
cache: 'npm'
- run: npm ci --legacy-peer-deps
- run: npm run coverage
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/test-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test main

on:
push:
branches: [main]

jobs:
test_pull_request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --legacy-peer-deps
- run: npm run coverage
- run: npm run build
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.12.1
20.11.0
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@

## Installation

```sh
npm install react-click-away-listener
```

or

```sh
yarn add react-click-away-listener
```

- It's quite **small** in size! Just [![Bundlephobia](https://img.shields.io/bundlephobia/min/react-click-away-listener.svg?style=flat-square&label "Bundle size (minified)")](https://bundlephobia.com/result?p=react-click-away-listener) minified, or [![Bundlephobia](https://img.shields.io/bundlephobia/minzip/react-click-away-listener.svg?style=flat-square&label "Bundle size (minified+gzipped)")](https://bundlephobia.com/result?p=react-click-away-listener) minified & gzipp’d.
- It's quite **small** in size! Just [![Bundlephobia](https://img.shields.io/bundlephobia/min/react-click-away-listener.svg?style=flat-square&label 'Bundle size (minified)')](https://bundlephobia.com/result?p=react-click-away-listener) minified, or [![Bundlephobia](https://img.shields.io/bundlephobia/minzip/react-click-away-listener.svg?style=flat-square&label 'Bundle size (minified+gzipped)')](https://bundlephobia.com/result?p=react-click-away-listener) minified & gzipp’d.
- It's built with **TypeScript**.
- It works with [React Portals](https://reactjs.org/docs/portals.html) ([v2.0.0](https://github.com/ooade/react-click-away-listener/releases/tag/v2.0.0) onwards).
- It supports **mouse**, **touch** and **focus** events.
Expand All @@ -37,7 +43,10 @@ const App = () => {
return (
<div id="app">
<ClickAwayListener onClickAway={handleClickAway}>
<div> Triggers whenever a click event is registered outside this div element </div>
<div>
{' '}
Triggers whenever a click event is registered outside this div element{' '}
</div>
</ClickAwayListener>
</div>
);
Expand Down Expand Up @@ -66,11 +75,11 @@ If you have multiple child components to pass, you can simply wrap them around a
```jsx
// Assume the `handleClickAway` function is defined.
<ClickAwayListener onClickAway={handleClickAway}>
<>
<p>First paragraph</p>
<button>Example Button</button>
<p>Second paragraph</p>
</>
<>
<p>First paragraph</p>
<button>Example Button</button>
<p>Second paragraph</p>
</>
</ClickAwayListener>
```

Expand All @@ -79,21 +88,18 @@ Or if you only have text nodes, you can also wrap them in a [React Fragment](htt
```jsx
// Assume the `handleClickAway` function is defined.
<ClickAwayListener onClickAway={handleClickAway}>
<>
First text node
Second text node
</>
<>First text node Second text node</>
</ClickAwayListener>
```

## Props

| Name | Type | Default | Description |
| ----------- | ----------------------------------| ------------- |---------------------------------------------------------- |
| onClickAway | (event) => void | | Fires when a user clicks outside the click away component |
| mouseEvent | 'click' \|<br/>'mousedown' \|<br/>'mouseup'| 'click' | The mouse event type that gets fired on ClickAway |
| touchEvent | 'touchstart' \|<br/>'touchend' | 'touchend' | The touch event type that gets fired on ClickAway |
| focusEvent | 'focusin' \|<br/>'focusout' | 'focusin' | The focus event type that gets fired on ClickAway |
| Name | Type | Default | Description |
| ----------- | ------------------------------------------- | ---------- | --------------------------------------------------------- |
| onClickAway | (event) => void | | Fires when a user clicks outside the click away component |
| mouseEvent | 'click' \|<br/>'mousedown' \|<br/>'mouseup' | 'click' | The mouse event type that gets fired on ClickAway |
| touchEvent | 'touchstart' \|<br/>'touchend' | 'touchend' | The touch event type that gets fired on ClickAway |
| focusEvent | 'focusin' \|<br/>'focusout' | 'focusin' | The focus event type that gets fired on ClickAway |

## Examples

Expand Down
20 changes: 10 additions & 10 deletions __tests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('ClickAway Listener', () => {
fireEvent[fireEventFn](getByText(/A button/i));
fireEvent[fireEventFn](getByText(/A text element/i));
fireEvent[fireEventFn](getByText(/Hello World/i));
expect(handleClickAway).toBeCalledTimes(2);
expect(handleClickAway).toHaveBeenCalledTimes(2);
}
);

Expand Down Expand Up @@ -107,7 +107,7 @@ describe('ClickAway Listener', () => {
fireEvent[fireEventFn](getByText(/A button/i));
fireEvent[fireEventFn](getByText(/A text element/i));
fireEvent[fireEventFn](getByText(/Hello World/i));
expect(handleClickAway).toBeCalledTimes(2);
expect(handleClickAway).toHaveBeenCalledTimes(2);
}
);

Expand Down Expand Up @@ -136,7 +136,7 @@ describe('ClickAway Listener', () => {
fireEvent[fireEventFn](getByText(/A button/i));
fireEvent[fireEventFn](getByText(/A text element/i));
fireEvent[fireEventFn](getByText(/Hello World/i));
expect(handleClickAway).toBeCalledTimes(2);
expect(handleClickAway).toHaveBeenCalledTimes(2);
}
);

Expand Down Expand Up @@ -168,14 +168,14 @@ describe('ClickAway Listener', () => {
fireEvent.click(getByTestId('text-one'));
fireEvent.click(getByTestId('hello-world'));
fireEvent.click(getByTestId('some-other-button-one'));
expect(handleClickAway).toBeCalledTimes(3);
expect(handleClickAway).toHaveBeenCalledTimes(3);

// 4 from the previous ones, and the 3 new ones
fireEvent.click(getByTestId('button-two'));
fireEvent.click(getByTestId('text-two'));
fireEvent.click(getByTestId('foo-bar'));
fireEvent.click(getByTestId('some-other-button-two'));
expect(handleClickAway2).toBeCalledTimes(7);
expect(handleClickAway2).toHaveBeenCalledTimes(7);
});

const Input = React.forwardRef<HTMLInputElement>((props, ref) => {
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('ClickAway Listener', () => {

fireEvent.click(getByText(/A button/i));
fireEvent.click(getByText(/A text element/i));
expect(handleClickAway).toBeCalledTimes(2);
expect(handleClickAway).toHaveBeenCalledTimes(2);
expect(result.current.ref).toStrictEqual(inputRef);
});

Expand All @@ -234,8 +234,8 @@ describe('ClickAway Listener', () => {

fireEvent.click(getByText('Hello World'));
fireEvent.click(getByText('The new boston'));
expect(handleClickAway).toBeCalledTimes(1);
expect(handleClick).toBeCalledTimes(1);
expect(handleClickAway).toHaveBeenCalledTimes(1);
expect(handleClick).toHaveBeenCalledTimes(1);
});

it('should work with function refs', () => {
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('ClickAway Listener', () => {
buttonRef.click();
divRef.click();
expect(buttonRef).toHaveProperty('type', 'submit');
expect(handleClickAway).toBeCalledTimes(1);
expect(handleClickAway).toHaveBeenCalledTimes(1);
});

it('should work with Portals', () => {
Expand Down Expand Up @@ -311,6 +311,6 @@ describe('ClickAway Listener', () => {
jest.advanceTimersByTime(0);
fireEvent.click(getByText(/Hello World/i));
fireEvent.click(getByText(/A button/i));
expect(handleClickAway).toBeCalledTimes(1);
expect(handleClickAway).toHaveBeenCalledTimes(1);
});
});
Loading
Loading