slate icon indicating copy to clipboard operation
slate copied to clipboard

fix selecting mention element in android, can't evoke the keyboard

Open YaoKaiLun opened this issue 2 years ago • 7 comments

Description In android, once selecting an inline void element, the keyboard doesn't be evoked, unless we set it's contenteditable to be true, like below

image

But it will make the children (a zero width node) to be contenteditable. So we should disable it's inputting at the beforeinput event.

Issue Fixes: https://github.com/ianstormtaylor/slate/issues/5183

Example

https://www.slatejs.org/examples/mentions

before:

https://user-images.githubusercontent.com/11460856/219867021-ca1b3937-3fc1-4986-8c4d-1744e567d846.mp4

after:

https://user-images.githubusercontent.com/11460856/219867027-4848f8dd-bc28-4c69-bb57-c189f3fb7158.mp4

Checks

  • [x] The new code matches the existing patterns and styles.
  • [ ] The tests pass with yarn test.
  • [x] The linter passes with yarn lint. (Fix errors with yarn fix.)
  • [x] The relevant examples still work. (Run examples with yarn start.)
  • [ ] You've added a changeset if changing functionality. (Add one with yarn changeset add.)

YaoKaiLun avatar Feb 18 '23 12:02 YaoKaiLun

⚠️ No Changeset found

Latest commit: 88b91e8ad312b0618d709540403bf6a2005ce2f1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Feb 18 '23 12:02 changeset-bot[bot]

@BitPhinix please review!

YaoKaiLun avatar Feb 18 '23 13:02 YaoKaiLun

Not a huge fan of this approach. Having the nodes contenteditable will likely mess with autocomplete and unexpected behaviour especially on more complex void nodes. There are other hacks to prevent the keyboard from closing when selecting inline void nodes, like adding pseudo elements with (zero-width) spaces around them via css.

BitPhinix avatar Feb 18 '23 13:02 BitPhinix

Allright, I'd try the pseudo elements method.

YaoKaiLun avatar Feb 18 '23 13:02 YaoKaiLun

@BitPhinix can you provide an example of the approach you had in mind? I played with a few different variations using ::before / ::after pseudo elements with zero-width space content on void inline nodes, to no avail.

clauderic avatar Feb 23 '23 16:02 clauderic

I use the following component for fixing this in general for inlines, not sure if this resolves your issue on android though. You use it by placing this before and after children in your inline component.

// Put this at the start and end of an inline component to work around this Chromium bug:
// https://bugs.chromium.org/p/chromium/issues/detail?id=1249405
// Necessary when the component has no padding on the sides
export const InlineChromiumBugfix = () => (
  <span
    contentEditable={false}
    css={css`
      font-size: 0;
    `}
  >
    ${String.fromCodePoint(160) /* Non-breaking space */}
  </span>
)

bryanph avatar Feb 24 '23 11:02 bryanph

@bryanph I tried different variations of your suggestion on Android but haven't had any success so far.

The only solution I've found that works so far is the one described in this PR, but I would love if we could find a solution that doesn't involve consumers having to handle Android-specific edge cases in the markup of their inline void nodes.

clauderic avatar Feb 28 '23 21:02 clauderic