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

fix: Inconsistent use of accents in Safari #16 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blacktail
Copy link

…s enabled

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #18 (8ee80c4) into master (12dc37f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 8ee80c4 differs from pull request most recent head 8f41453. Consider uploading reports for the commit 8f41453 to get more accurate results

@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
+ Coverage   98.02%   98.05%   +0.02%     
==========================================
  Files           3        3              
  Lines         152      154       +2     
  Branches       45       47       +2     
==========================================
+ Hits          149      151       +2     
  Misses          3        3              
Impacted Files Coverage Δ
src/ResizableTextArea.tsx 98.41% <100.00%> (+0.05%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@blacktail blacktail force-pushed the fix-accent-input-problems-safari branch from 22401aa to b63ed56 Compare July 18, 2022 06:57
@blacktail
Copy link
Author

blacktail commented Jul 18, 2022

Root cause:
This MR fix a problem in firefox about two years ago:
ant-design/ant-design#21870

Added this code block:

fixFirefoxAutoScroll = () => {
    try {
      if (document.activeElement === this.textArea) {
        const currentStart = this.textArea.selectionStart;
        const currentEnd = this.textArea.selectionEnd;
        this.textArea.setSelectionRange(currentStart, currentEnd);
      }
    } catch (e) {}
  };

This code will cause many safari problems regard of composition event. the fixFirefoxAutoScroll should only be called when the browser is firefox. But currently, it will also be called in safari or other browsers

@blacktail blacktail force-pushed the fix-accent-input-problems-safari branch 3 times, most recently from 61a4ee9 to e5cf396 Compare July 18, 2022 08:21
@@ -109,7 +109,10 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
// https://github.com/ant-design/ant-design/issues/21870
fixFirefoxAutoScroll() {
try {
if (document.activeElement === this.textArea) {
if (
navigator.userAgent.includes('Firefox') &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use UA but feature detection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari or Firefox.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed,

use window.hasOwnProperty('mozInnerScreenX') instead

@blacktail blacktail force-pushed the fix-accent-input-problems-safari branch from e5cf396 to 8f41453 Compare July 22, 2022 03:30
@LFDanLu
Copy link

LFDanLu commented Aug 23, 2022

QQ, is this accents stuff not a problem in Firefox as well? Was wondering if you've tried doing something like

      if (inputValue?.startsWith(lastInputValue.current)) {
        input.scrollTop = input.scrollHeight;
      }

instead of using the selectionStart/selectionEnd approach for FF autoscroll. Just ran into a similar problem in React Spectrum and was curious on any prior discoveries you've made when testing here.

EDIT: Never mind, did some more testing and the above is buggy, breaks if you are typing in the middle and your cursor then exits the visible area and some other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants