Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 11 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class ReactQuill extends React.Component<ReactQuillProps, ReactQuillState> {
editor.setContents(delta);
postpone(() => this.setEditorSelection(editor, selection));
}

if (this.editor && this.props.tabIndex !== prevProps.tabIndex) {
this.setEditorTabIndex(this.editor, this.props.tabIndex);
}
}

instantiateEditor(): void {
Expand Down Expand Up @@ -402,9 +406,13 @@ class ReactQuill extends React.Component<ReactQuillProps, ReactQuillState> {
}
}

setEditorTabIndex(editor: Quill, tabIndex: number) {
if (editor?.scroll?.domNode) {
(editor.scroll.domNode as HTMLElement).tabIndex = tabIndex;
setEditorTabIndex(editor: Quill, tabIndex?: number) {
const node = editor?.scroll?.domNode as HTMLElement | undefined;
if (!node) return;
if (tabIndex != null) {
node.tabIndex = tabIndex;
} else {
node.removeAttribute('tabindex');
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { Quill } = require('../lib/index');
const {
mountReactQuill,
getQuillInstance,
getQuillDOMNode,
getQuillContentsAsHTML,
setQuillContentsFromHTML,
withMockedConsole,
Expand Down Expand Up @@ -185,6 +186,13 @@ describe('<ReactQuill />', function() {
expect(wrapper.getDOMNode().querySelector('div#venus')).not.to.be.null;
});

it('updates tabIndex on the editor when the prop changes', () => {
const wrapper = mountReactQuill({ tabIndex: 3 });
expect(getQuillDOMNode(wrapper).tabIndex).to.equal(3);
wrapper.setProps({ tabIndex: 5 });
expect(getQuillDOMNode(wrapper).tabIndex).to.equal(5);
});

/**
* This can't be tested with the current state of JSDOM.
* The selection functions have been shimmed in this test suite,
Expand Down