Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing for more fine tuning of Quill without rewriting RichTextInput #3714

Merged
merged 6 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ You can customize the rich text editor toolbar using the `toolbar` attribute, as
<RichTextInput source="body" toolbar={[ ['bold', 'italic', 'underline', 'link'] ]} />
```

If you need more customization, you can access the quill object through the `quillInit` callback that will be called just after its initialization.

```js
const quillInit = quill => quill.getModule('toolbar').addHandler('bold', function (value) {
this.quill.format('bold', value)
});

// ...

<RichTextInput source="text" quillInit={quillInit}/>
```

## `<SelectInput>`

To let users choose a value in a list using a dropdown, use `<SelectInput>`. It renders using [Material ui's `<Select>`](http://v1.material-ui.com/api/select). Set the `choices` attribute to determine the options (with `id`, `name` tuples):
Expand Down
12 changes: 12 additions & 0 deletions packages/ra-input-rich-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ You can customize the rich text editor toolbar using the `toolbar` attribute, as
<RichTextInput source="body" toolbar={[ ['bold', 'italic', 'underline', 'link'] ]} />
```

If you need more customization, you can access the quill object through the `quillInit` callback that will be called just after its initialization.

```js
const quillInit = quill => quill.getModule('toolbar').addHandler('bold', function (value) {
this.quill.format('bold', value)
});

// ...

<RichTextInput source="text" quillInit={quillInit}/>
```

## License

This library is licensed under the MIT License, and sponsored by [marmelab](http://marmelab.com).
5 changes: 5 additions & 0 deletions packages/ra-input-rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class RichTextInput extends Component {
}),
]),
fullWidth: PropTypes.bool,
quillInit: PropTypes.func,
};

static defaultProps = {
Expand All @@ -52,6 +53,10 @@ export class RichTextInput extends Component {
...options,
});

if (this.props.quillInit) {
this.props.quillInit(this.quill);
}

this.quill.setContents(this.quill.clipboard.convert(value));

this.editor = this.divRef.querySelector('.ql-editor');
Expand Down