inline Editor in shadow dom: Does not work on iOS
madeInLagny opened this issue · 5 comments
Affected part of DeckDeckGo
- [ X] Web Components
Issue with inline Editor
Reproduction
Steps to reproduce:
Import lit
import { html, css } from 'lit-element';
Import inline Editor by cdn
<script type="module" src="https://unpkg.com/@deckdeckgo/inline-editor@latest/dist/deckdeckgo-inline-editor/deckdeckgo-inline-editor.esm.js"></script>
listen to selectionchange event:
connectedCallback() {
super.connectedCallback();
document.addEventListener('selectionchange', () => {
// Obtain the selection from component's shadow root
this.selection = this.shadowRoot?.getSelection();
if (!this.selection) {
return;
}
// Obtain the inline-editor element
// Here we assume that the element is added directly to document
this.inlineEditor = this.shadowRoot.getElementById(
'deckgo-inline-editor'
);
this.inlineEditor.displayTools(this.selection);
});
}
Add editor in HTML
render() {
return html`
<deckgo-inline-editor
id="deckgo-inline-editor"
handle-global-events="false"
>
</deckgo-inline-editor>
<h1 class="h1" contenteditable>Inline Editor Test</h1>
Expected Behavior
Inline editor should appear below text selection.
Actual Behavior
Works on Android + Windows in Chrome and Edge.
Does not work on iOS (tested on Safari and Chrome).
I remember having issue with the selectionchange
event on iOS. Did you double check that displayTools
is effectively called on iOS?
If yes and if it seems all good, you can also try to set mobile
to false
. Per default it will detect mobile devices and will display to component with a fixed value at the top or bottom of the screen because of the display of the virtual keyboard on mobile devices.
selectionchange
event is caught by the listener, even on iOS. It breaks at this.shadowRoot?.getSelection()
. I googled around and got confused on whether that method is available on iOS or not.
Yes it should but, worth double checking.
Like I said in my previous msg:
- check that you effectively call
displayTools
- if it does, then try maybe to set
mobile
tofalse
If still does not work, you are most welcome to provide a sample repo to reproduce the error or, why not, a PR to fix the issue.
In that case there is not much we can do, the issue is not related to the web component.
Therefore I close this issue.
Of course if you would fix the call and if the component would still not be displayed, ping me to reopen it.
Good luck 🤞