Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 5a732d0

Browse files
committed
Updating the docs
1 parent 0a78cad commit 5a732d0

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

docs/api/Control.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function changeAndSubmit(model, value) {
261261
- Since `changeAction` expects an action creator and `redux-thunk` is used, you can asynchronously dispatch actions (like the example above).
262262

263263
<h2 id="prop-controlProps"></h2>
264-
### `controlProps={{...}}`
264+
## `controlProps={{...}}`
265265
_(Object)_: A mapping of control-specific props that will be applied directly to the rendered control. In some cases, this can be a safer way of applying props, especially if there are naming conflicts between `<Control>`-specific props (such as `"model"`) and props that need to go on the rendered control (e.g., `<input {...props} />`).
266266

267267
The normal behavior is that any extraneous props on `<Control>` that are not part of `Control.propTypes` (which are documented here) will be given to the rendered input.
@@ -278,7 +278,7 @@ Example:
278278
```
279279

280280
<h2 id="prop-component"></h2>
281-
### `component={...}`
281+
## `component={...}`
282282
_(Function | String | Node)_: A custom component can be passed into the `component={...}` prop, and standard control props and event handlers (such as `onChange`, `onBlur`, `onFocus`, `value`, etc.) will be mapped as expected:
283283

284284
```jsx
@@ -294,7 +294,7 @@ const MyTextInput = (props) => <input className="my-input" {...props} />;
294294
```
295295

296296
<h2 id="prop-ignore"></h2>
297-
### `ignore={[...]}`
297+
## `ignore={[...]}`
298298
_(String | Array)_: The event(s) that you want the `<Control>` to ignore. This can be good for performance and/or for de-cluttering the console log.
299299

300300
For instance, if you don't care whether a `<Control>` is focused or blurred:
@@ -307,7 +307,7 @@ For instance, if you don't care whether a `<Control>` is focused or blurred:
307307
/>
308308
```
309309

310-
### `disabled={...}`
310+
## `disabled={...}`
311311
_(Any)_: The `disabled` prop works just like you'd expect for controls that support the HTML5 `disabled` attribute.
312312

313313
However, in `<Control>`, it can be a boolean, or a function, string, or object as a [Lodash iteratee](https://lodash.com/docs#iteratee).
@@ -329,3 +329,13 @@ For example:
329329
- `disabled={(fieldValue) => !fieldValue.valid}` will call the function provided with the `fieldValue` to determine its `disabled` state.
330330

331331
(since: version 1.3.0)
332+
333+
## `getRef={() => ...}`
334+
_(Function)_: Calls the callback provided to the `getRef` prop with the node instance. Similar to `ref`.
335+
336+
```jsx
337+
<Control.text
338+
model="user.name"
339+
getRef={(node) => this.attach(node)}
340+
/>
341+
```

docs/api/Field.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ const { showTerritories } = this.props;
5555
<StatePicker territories={showTerritories} />
5656
</Field>
5757
```
58+
59+
### `getRef={() => ...}`
60+
_(Function)_: Calls the callback provided to the `getRef` prop with the node instance. Similar to `ref`.
61+
62+
```jsx
63+
<Control.text
64+
model="user.name"
65+
getRef={(node) => this.attach(node)}
66+
/>
67+
```

docs/api/Form.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const passwordsMatch = ({ password, confirmPassword }) => {
2525
type="email"
2626
model=".email"
2727
/>
28-
28+
2929
<Control
3030
type="password"
3131
model=".password"
@@ -116,10 +116,10 @@ class MyForm extends React.Component {
116116
.then((res) => {
117117
// ...
118118
});
119-
119+
120120
dispatch(actions.submit('user', userPromise));
121121
}
122-
122+
123123
render() {
124124
return (
125125
<Form
@@ -163,7 +163,7 @@ class MyForm extends React.Component {
163163
// logs errors for user.email
164164
console.log(userForm.email.errors);
165165
}
166-
166+
167167
render() {
168168
return (
169169
<Form
@@ -208,3 +208,13 @@ _(Function)_ The handler function that is called with the form's model value whe
208208
### Notes
209209
- This is also an optional but useful property, especially if you are using [local forms](../guides/local.md).
210210
- Remember: the _model value_ is the value of the form's model, specified by the `model="..."` prop. The entire model value will be passed in.
211+
212+
## `getRef={() => ...}`
213+
_(Function)_: Calls the callback provided to the `getRef` prop with the node instance. Similar to `ref`.
214+
215+
```jsx
216+
<Control.text
217+
model="user.name"
218+
getRef={(node) => this.attach(node)}
219+
/>
220+
```

docs/guides/faqs.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,21 @@ const BirthDate = ({forModel}) => (
5050
<Control model=".day" placeholder="Day" />
5151
<Control model=".month" placeholder="Month" />
5252
<Control model=".year" placeholder="Year" />
53-
</Form>
53+
</Form>
5454
);
5555

5656
export default BirthDate;
5757
```
5858

59+
### How do I get the component instance? `ref={...}` doesn't work.
60+
61+
Use `getRef={(node) => ...}` in place of `ref`. This is due to the fact that React treats the `ref` prop as a "magic" prop that doesn't get propagated down through wrapped components.
62+
63+
You can use `getRef` on `<Field>`, `<Control>`, `<Form>`, or `<LocalForm>` components.
64+
65+
```jsx
66+
<Control.text
67+
model="user.name"
68+
getRef={(node) => this.attach(node)}
69+
/>
70+
```

0 commit comments

Comments
 (0)