Skip to content

Commit

Permalink
Merge pull request #58 from niuware/development
Browse files Browse the repository at this point in the history
Expose focus method
  • Loading branch information
niuware authored Nov 18, 2019
2 parents 034700a + 512024c commit de06c76
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
19 changes: 13 additions & 6 deletions examples/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ const App = () => {

return (
<div>
Load example: &nbsp;
Choose example: &nbsp;
<button onClick={() => setSample(<Basic />)}>Basic</button>
<button onClick={() => setSample(<Theme />)}>Theme</button>
<button onClick={() => setSample(<RefSave />)}>RefSave</button>
<button onClick={() => setSample(<ReadOnly />)}>Read Only</button>
<button onClick={() => setSample(<Events />)}>Events</button>
<button onClick={() => setSample(<RefSave />)}>Ref Events</button>
<button onClick={() => setSample(<CustomControls />)}>Custom Controls</button>
<button onClick={() => setSample(<Decorators />)}>Decorators</button>
<button onClick={() => setSample(<InlineToolbar />)}>Inline Toolbar</button>
<button onClick={() => setSample(<CustomInlineToolbar />)}>Custom Inline Toolbar</button>
<button onClick={() => setSample(<AtomicCustomBlock />)}>Atomic Custom Block</button>
<button onClick={() => setSample(<ReadOnly />)}>Read Only</button>
<button onClick={() => setSample(<Events />)}>Events</button>
<button onClick={() => setSample(<LoadHTML />)}>Load from HTML</button>
<button onClick={() => setSample(<ResetValue />)}>Reset value</button>
<button onClick={() => setSample(<AtomicCustomBlock />)}>Atomic Custom Block</button>
{sample}
<div style={{
margin: "20px 0"
}}>
<p>
<strong>{sample.type.name}</strong> example:
</p>
{sample}
</div>
</div>
)
}
Expand Down
11 changes: 11 additions & 0 deletions examples/ref-save/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const RefSave: FunctionComponent = () => {
(ref as any).current.save()
}

const handleFocus = () => {
(ref as any).current.focus()
}

const handleSave = (data: string) => {
console.log(data)
}
Expand All @@ -23,6 +27,13 @@ const RefSave: FunctionComponent = () => {
onClick={handleClick}>
Save
</button>
<button style={{
marginLeft: 5,
padding: 5
}}
onClick={handleFocus}>
Focus
</button>
<MUIRichTextEditor
label="Type something here..."
onSave={handleSave}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-rte",
"version": "1.9.1",
"version": "1.9.2",
"description": "Material-UI Rich Text Editor and Viewer",
"keywords": [
"material-ui",
Expand Down
3 changes: 3 additions & 0 deletions src/MUIRichTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ const MUIRichTextEditor: RefForwardingComponent<any, IMUIRichTextEditorProps> =
* Expose methods
*/
useImperativeHandle(ref, () => ({
focus: () => {
handleFocus()
},
save: () => {
handleSave()
},
Expand Down

0 comments on commit de06c76

Please sign in to comment.