Skip to content

Commit 4531948

Browse files
committed
feat: (joshwnj#174) Introduce onCheck event to register a callback that is executed whenever the element is checked
1 parent b32ab63 commit 4531948

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Props
7373
----
7474

7575
- `onChange`: callback for whenever the element changes from being within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)`
76+
- `onCheck`: callback for whenever the element being checked if it is within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)` after the check is done. - Same as `onChange` but called even if the visibility hasn't changed.
7677
- `active`: (default `true`) boolean flag for enabling / disabling the sensor. When `active !== true` the sensor will not fire the `onChange` callback.
7778
- `partialVisibility`: (default `false`) consider element visible if only part of it is visible. Also possible values are - 'top', 'right', 'bottom', 'left' - in case it's needed to detect when one of these become visible explicitly.
7879
- `offset`: (default `{}`) with offset you can define amount of px from one side when the visibility should already change. So in example setting `offset={{top:10}}` means that the visibility changes hidden when there is less than 10px to top of the viewport. Offset works along with `partialVisibility`

visibility-sensor.js

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default class VisibilitySensor extends React.Component {
3838

3939
static propTypes = {
4040
onChange: PropTypes.func,
41+
onCheck: PropTypes.func,
4142
active: PropTypes.bool,
4243
partialVisibility: PropTypes.oneOfType([
4344
PropTypes.bool,
@@ -321,6 +322,7 @@ export default class VisibilitySensor extends React.Component {
321322
if (this.props.onChange) this.props.onChange(isVisible);
322323
}
323324

325+
if (this.props.onCheck) this.props.onCheck(isVisible);
324326
return state;
325327
};
326328

0 commit comments

Comments
 (0)