Skip to content

Commit ed071af

Browse files
committed
Introduce containerProps
1 parent 745646c commit ed071af

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ All of these props are optional and some also come with a default value. However
5656
| autoFocus | Boolean | `false` | Focus the input automatically as soon as it is rendered. |
5757
| removeDefaultStyles | Boolean | `false` | Completely remove any styles that are not required for the component to work properly. This is useful if you want to override the default styles (see [Custom Styling](#custom-styling)). |
5858
| debug | Boolean | `false` | Reveal what is going on behind the scenes, which might come in handy when trying to better understand the component. Obviously you don't want to use this in production. 😄 |
59-
| inputProps | Object | `{}` | These props get forwarded to the input element. |
59+
| inputProps | Object | `{}` | The properties of this object get forwarded as props to the input element. |
60+
| containerProps | Object | `{}` | The properties of this object get forwarded as props to the container element. |
6061
| classNames | Object | `{}` | CSS class names to add to the specified elements. For more details see [Custom Styling](#custom-styling). |
6162
| onChange | Function | - | Callback function that gets called with the string value whenever it changes. |
6263
| onFocus | Function | - | Callback function that gets called when the component obtains focus. |
6364
| onBlur | Function | - | Callback function that gets called when the component loses focus. |
64-
| (any other prop) | Any | - | Any props not listed above will be directly forwarded to the `container` element. |
6565

6666
## Custom Styling
6767

@@ -122,6 +122,12 @@ Have a look at this example:
122122
}
123123
```
124124

125+
## Migration Guide: `v2` --> `v3`
126+
127+
- **Additional props**
128+
129+
Custom props are no longer forwarded to the container element. Use the new prop `containerProps` instead and specify the custom props in object literal form.
130+
125131
## Migration Guide: `v0.1.x` --> `v2`
126132

127133
- **prop: `input`**

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface VerificationInputProps {
77
removeDefaultStyles?: boolean;
88
debug?: boolean;
99
inputProps?: object;
10+
containerProps?: object;
1011
classNames?: {
1112
container?: string;
1213
character?: string;

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ const VerificationInput = forwardRef(
1717
removeDefaultStyles,
1818
debug,
1919
inputProps,
20+
containerProps,
2021
classNames: classes,
2122
onChange,
2223
onFocus,
2324
onBlur,
24-
...restProps
2525
},
2626
ref
2727
) => {
@@ -104,7 +104,7 @@ const VerificationInput = forwardRef(
104104
"vi__container--default": !removeDefaultStyles,
105105
})}
106106
onClick={() => inputRef.current.focus()}
107-
{...restProps}
107+
{...containerProps}
108108
>
109109
{[...Array(length)].map((_, i) => (
110110
<div
@@ -149,6 +149,7 @@ VerificationInput.propTypes = {
149149
removeDefaultStyles: PropTypes.bool,
150150
debug: PropTypes.bool,
151151
inputProps: PropTypes.object,
152+
containerProps: PropTypes.object,
152153
classNames: PropTypes.shape({
153154
container: PropTypes.string,
154155
character: PropTypes.string,
@@ -168,6 +169,7 @@ VerificationInput.defaultProps = {
168169
removeDefaultStyles: false,
169170
debug: false,
170171
inputProps: {},
172+
containerProps: {},
171173
classNames: {},
172174
};
173175

src/verification-input.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ describe("VerificationInput", () => {
350350
expect(screen.getByRole("textbox")).toHaveAttribute("type", "tel");
351351
});
352352

353-
it("should forward unknown props to container element", () => {
354-
render(<VerificationInput prop="value" />);
353+
it("should forward containerProps to container element", () => {
354+
render(<VerificationInput containerProps={{ prop: "value" }} />);
355355

356356
expect(screen.getByTestId("container")).toHaveAttribute("prop", "value");
357357
});

0 commit comments

Comments
 (0)