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

🐞 - InputInline has broken scroll in Safari / Firefox #7552

Closed
2 of 9 tasks
goodday21 opened this issue May 27, 2024 · 3 comments · Fixed by #9818
Closed
2 of 9 tasks

🐞 - InputInline has broken scroll in Safari / Firefox #7552

goodday21 opened this issue May 27, 2024 · 3 comments · Fixed by #9818
Assignees
Labels
P1 This issue has high priority S2 This issue has medium severity

Comments

@goodday21
Copy link

goodday21 commented May 27, 2024

Playground Link

No response

Description

Браузер - Safari.

Компонент - https://taiga-ui.dev/components/input-inline#heading

Шаги:

  1. нажать на иконку редактирования у элемента "Page heading"
  2. ввести длинную строку, более 150 символов
  3. сохранить изменения
  4. снова нажать на иконку редактирования
  5. попробовать поменять строку

Ожидаемый результат: фокус установлен в конец строки, пользователь может передвигать курсор по тексту и редактировать его
Фактический результат: фокус остается на начале строки. Если пользователь работает с концом строки, то он не видит, что вводит

Angular version

No response

Taiga UI version

3.80.0

Which browsers have you used?

  • Chrome
  • Firefox
  • Safari
  • Edge

Which operating systems have you used?

  • macOS
  • Windows
  • Linux
  • iOS
  • Android
@waterplea waterplea added P1 This issue has high priority S2 This issue has medium severity and removed state: need triage labels Jul 9, 2024
@waterplea
Copy link
Collaborator

Safari does not dispatch scroll events for inputs. We need to use additional keypress events, selection change events and whatnot to be able to adjust text-indent to input scroll. Maybe it's even easier to just use silent animation frame for polling, but that might cause a lot of CSS reflow.

@splincode splincode removed the bug label Nov 11, 2024
@nsbarsukov
Copy link
Member

nsbarsukov commented Nov 21, 2024

Just some intermediate investigations

We can replace the following logic

protected indent = -1;
protected onScroll(target: EventTarget | null): void {
if (tuiIsElement(target) && tuiIsInput(target)) {
this.indent = -target.scrollLeft - 1; // -1 for Safari (see styles)
}
}

with

protected indent$ = merge(
    fromEvent(this.element, 'scroll', {capture: true}), // Only Chrome emits this event for <input />
    // Chrome does not fire `selectionchange` on deletion (but do it on insertion) ¯\_(ツ)_/¯
    fromEvent(this.element, 'selectionchange', {capture: true}), // Firefox + Safari fallback
    // Chrome & Safari scrolls input to the beginning on blur
    // Firefox – keeps the same scrollLeft position on blur
    fromEvent(this.element, 'focusout').pipe(
        concatMap(
            (x) => of(x).pipe(delay(0)), // Without delay `scrollLeft` is not yet updated
        ),
    ),
).pipe(
    map(({target}) => target),
    filter((x): x is HTMLInputElement => tuiIsElement(x) && tuiIsInput(x)),
    map(
        ({scrollLeft}) => -scrollLeft - 1, // -1 for Safari (see styles)
    ),
);

However, it still does fully solves all issue for Safari / Firefox.
Try to insert many characters and the use many Backspaces then.
The content will slightly shift to the left: textContent of ghost-span updates faster than textIndent calculations (shrinking of ghost-span should be AFTER textIndent calculations).

<span
class="t-before"
[style.text-indent.px]="indent"
[textContent]="value"
></span>

Even if we delay update of textContent (by adding delay(0) to indent$ stream) - insertion of new character will be broken (we should increase size of ghost-span BEFORE textIndent calculations).

@nsbarsukov
Copy link
Member

TODO

Discuss this PR with @waterplea

Which problem was solved by this PR ?
Could we make <input />-element visible again (and solve that problem in another way) ?
If it was about vertical alignment with another inline-elements – probably we could just remove overflow:hidden from the host (to not break baseline of host inline block).

display: inline-block;
overflow: hidden;

@nsbarsukov nsbarsukov changed the title 🐞 - Safari - Компонент input-inline - При редактировании длинной строки заголовка фокус всегда остается на начале строки 🐞 - InputInline has broken scroll in Safari / Firefox Nov 21, 2024
@nsbarsukov nsbarsukov self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 This issue has high priority S2 This issue has medium severity
Development

Successfully merging a pull request may close this issue.

4 participants