Skip to content

Commit

Permalink
Merge pull request #12 from createnl/forward-refs
Browse files Browse the repository at this point in the history
Forward checkbox refs
  • Loading branch information
AlexLisenkov authored Mar 5, 2020
2 parents ec33a2f + 97c8928 commit 4498e8f
Show file tree
Hide file tree
Showing 16 changed files with 4,851 additions and 2,820 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ module.exports = {
"jest",
],
"rules": {
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
};
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,31 @@ The value of an onChange parameter looks like:
]
```
Note that the value of the NoneCheckerCheckbox will not be passed.
### Accessing the native input
The `Checkbox`, `AllCheckerCheckbox` and `NoneCheckerCheckboxes` are nothing more than controlled native input elements and uses the [forwardRef](https://reactjs.org/docs/forwarding-refs.html) function for you to pass your ref to.
This enables you to control the DOM node and for example focus on the element.
``` jsx harmony
import React from "react";
import { AllCheckerCheckbox, Checkbox, CheckboxGroup } from '@createnl/grouped-checkboxes';

const MyGroupedCheckboxes = (props) => {
const checkboxRef = React.createRef();

React.useEffect(() => {
if (checkboxRef.current) {
// Focus on the input element
checkboxRef.current.focus();
}
}, [checkboxRef])

return (
<CheckboxGroup>
<AllCheckerCheckbox />
<Checkbox ref={checkboxRef} value="option-1"/>
<Checkbox value="option-2" />
<Checkbox value="option-3" />
</CheckboxGroup>
);
};
8 changes: 3 additions & 5 deletions dist/AllCheckerCheckbox.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { FC } from 'react';
interface AllCheckerCheckboxProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
checked?: never;
}
declare const AllCheckerCheckbox: FC<AllCheckerCheckboxProps>;
import React, { ForwardRefExoticComponent, RefAttributes } from 'react';
declare type AllCheckerCheckboxProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & RefAttributes<HTMLInputElement>, 'checked'>;
declare const AllCheckerCheckbox: ForwardRefExoticComponent<AllCheckerCheckboxProps>;
export default AllCheckerCheckbox;
6 changes: 3 additions & 3 deletions dist/AllCheckerCheckbox.js

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

2 changes: 1 addition & 1 deletion dist/AllCheckerCheckbox.js.map

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

6 changes: 3 additions & 3 deletions dist/Checkbox.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
declare type CheckboxProps = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
declare const Checkbox: FC<CheckboxProps>;
import React, { ForwardRefExoticComponent, RefAttributes } from 'react';
declare type CheckboxProps = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & RefAttributes<HTMLInputElement>;
declare const Checkbox: ForwardRefExoticComponent<CheckboxProps>;
export default Checkbox;
6 changes: 3 additions & 3 deletions dist/Checkbox.js

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

2 changes: 1 addition & 1 deletion dist/Checkbox.js.map

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

8 changes: 3 additions & 5 deletions dist/NoneCheckerCheckbox.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { FC } from 'react';
interface NoneCheckerCheckboxProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
checked?: never;
}
declare const NoneCheckerCheckbox: FC<NoneCheckerCheckboxProps>;
import React, { ForwardRefExoticComponent, RefAttributes } from 'react';
declare type NoneCheckerCheckboxProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & RefAttributes<HTMLInputElement>, 'checked'>;
declare const NoneCheckerCheckbox: ForwardRefExoticComponent<NoneCheckerCheckboxProps>;
export default NoneCheckerCheckbox;
6 changes: 3 additions & 3 deletions dist/NoneCheckerCheckbox.js

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

2 changes: 1 addition & 1 deletion dist/NoneCheckerCheckbox.js.map

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

Loading

0 comments on commit 4498e8f

Please sign in to comment.