Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 3f96107

Browse files
committed
Add imperative API documentation
1 parent 01129cc commit 3f96107

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README-template.md

+24
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,31 @@ yarn add react-autocomplete
2525

2626
## API
2727

28+
### Props
29+
2830
${API_DOC}
31+
### Imperative API
32+
33+
In addition to the props there is an API available on the mounted element which is similar to that of `HTMLInputElement`. In other words: you can access most of the common `<input>` methods directly on an `Autocomplete` instance. An example:
34+
35+
```jsx
36+
class MyComponent extends Component {
37+
componentDidMount() {
38+
// Focus the input and select "world"
39+
this.input.focus()
40+
this.input.setSelectionRange(6, 11)
41+
}
42+
render() {
43+
return (
44+
<Autocomplete
45+
ref={el => this.input = el}
46+
value="hello world"
47+
...
48+
/>
49+
)
50+
}
51+
}
52+
```
2953

3054
# Development
3155
You can start a local development environment with `npm start`. This command starts a static file server on [localhost:8080](http://localhost:8080) which serves the examples in `examples/`. Hot-reload mechanisms are in place which means you don't have to refresh the page or restart the build for changes to take effect.

bin/generate-api-doc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function prepareDefaultValue (props) {
6868
function format (props) {
6969
return props.reduce((str, { name, type, required, description, defaultValue }) => {
7070
if (type) {
71-
return `${str}### \`${name}: ${TYPES[type.name]}\`${required ? '' : ' (optional)'}\n${defaultValue}${description}\n`
71+
return `${str}#### \`${name}: ${TYPES[type.name]}\`${required ? '' : ' (optional)'}\n${defaultValue}${description}\n`
7272
} else {
7373
throw new Error(`ERROR: \`${name}\` is present in \`defaultProps\` but not in \`propTypes\`!`)
7474
}

0 commit comments

Comments
 (0)