Skip to content

Commit 9797f0c

Browse files
committed
feat(text-editor): delegate focus to prosemirror
Makes sure to delegate the focus to prosemirror if the text editor get's the focus.
1 parent ed28b48 commit 9797f0c

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Element,
44
Event,
55
EventEmitter,
6+
Host,
67
Prop,
78
State,
89
Watch,
@@ -205,18 +206,20 @@ export class ProsemirrorAdapter {
205206
}
206207

207208
public render() {
208-
return [
209-
<div id="editor" />,
210-
<div class="toolbar">
211-
<limel-action-bar
212-
ref={(el) => (this.actionBarElement = el)}
213-
accessibleLabel="Toolbar"
214-
actions={this.actionBarItems}
215-
onItemSelected={this.handleActionBarItem}
216-
/>
217-
</div>,
218-
this.renderLinkMenu(),
219-
];
209+
return (
210+
<Host onFocus={this.handleFocus}>
211+
<div id="editor" />,
212+
<div class="toolbar">
213+
<limel-action-bar
214+
ref={(el) => (this.actionBarElement = el)}
215+
accessibleLabel="Toolbar"
216+
actions={this.actionBarItems}
217+
onItemSelected={this.handleActionBarItem}
218+
/>
219+
</div>
220+
{this.renderLinkMenu()}
221+
</Host>
222+
);
220223
}
221224

222225
renderLinkMenu() {
@@ -452,9 +455,9 @@ export class ProsemirrorAdapter {
452455
this.link = event.detail;
453456
};
454457

455-
public setFocus() {
458+
private handleFocus = () => {
456459
this.view?.focus();
457-
}
460+
};
458461

459462
private handleNewLinkSelection = (text: string, href: string) => {
460463
this.link.text = text;

src/components/text-editor/text-editor.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('limel-text-editor', () => {
2525
<span class="leading-outline"></span>
2626
<span class="trailing-outline"></span>
2727
</span>
28-
<limel-prosemirror-adapter aria-controls=${ariaControls[0]} contenttype="markdown" id=${ids[0]} language="en"></limel-prosemirror-adapter>
28+
<limel-prosemirror-adapter aria-controls=${ariaControls[0]} contenttype="markdown" id=${ids[0]} language="en" tabindex="0"></limel-prosemirror-adapter>
2929
</mock:shadow-root>
3030
</limel-text-editor>`);
3131
});
@@ -74,7 +74,7 @@ describe('limel-text-editor', () => {
7474
value: { attribute: 'value', value: 'test' },
7575
disabled: { attribute: 'tabindex', value: false },
7676
},
77-
['test', null],
77+
['test', '0'],
7878
],
7979
[
8080
{

src/components/text-editor/text-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { EditorUiType } from './types';
3030
*/
3131
@Component({
3232
tag: 'limel-text-editor',
33-
shadow: true,
33+
shadow: { delegatesFocus: true },
3434
styleUrl: 'text-editor.scss',
3535
})
3636
export class TextEditor implements FormComponent<string> {
@@ -244,7 +244,7 @@ export class TextEditor implements FormComponent<string> {
244244
value={this.value}
245245
aria-controls={this.helperTextId}
246246
id={this.editorId}
247-
tabindex={this.disabled ? -1 : undefined}
247+
tabindex={this.disabled ? -1 : 0}
248248
aria-disabled={this.disabled}
249249
language={this.language}
250250
triggerCharacters={this.triggers}

0 commit comments

Comments
 (0)