-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from SpareBank1/231-use-forwardRef-take-two
feat(ffe-form-react): Add support for forwarding refs
- Loading branch information
Showing
6 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
```js | ||
<React.Fragment> | ||
<Label htmlFor="textarea-example"> | ||
Beskriv skaden | ||
</Label> | ||
<Label htmlFor="textarea-example">Beskriv skaden</Label> | ||
<TextArea | ||
defaultValue="Dette er et tekstfelt for lengre tekster." | ||
id="textarea-example" | ||
rows="8" | ||
/> | ||
</React.Fragment> | ||
``` | ||
|
||
## Styr fokus med `ref` | ||
|
||
Du kan få en referanse til textarea-feltet ved å sende inn en `ref`-prop. Brukes typisk til å fokusere et felt programmatisk. | ||
|
||
```js | ||
const { TextArea } = require('.'); | ||
const { ButtonGroup, PrimaryButton } = require('../../ffe-buttons-react'); | ||
|
||
class Example extends React.Component { | ||
constructor() { | ||
super(); | ||
this.inputRef = React.createRef(); | ||
this.handleClick = this.handleClick.bind(this); | ||
} | ||
handleClick() { | ||
this.inputRef.current.focus(); | ||
} | ||
render() { | ||
return ( | ||
<React.Fragment> | ||
<TextArea | ||
ref={this.inputRef} | ||
placeholder="Trykk på knappen for fokus" | ||
/> | ||
<ButtonGroup> | ||
<PrimaryButton onClick={this.handleClick}> | ||
Klikk for å fokusere input | ||
</PrimaryButton> | ||
</ButtonGroup> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
<Example />; | ||
``` |