Hide scrollbar on input height animation
This commit is contained in:
parent
8dc136538a
commit
b9ab1c8a1c
@ -1,4 +1,5 @@
|
|||||||
import { getRichValue, isInputEmpty } from "../helpers/dom";
|
import { getRichValue, isInputEmpty } from "../helpers/dom";
|
||||||
|
import { debounce } from "../helpers/schedulers";
|
||||||
import { checkRTL } from "../helpers/string";
|
import { checkRTL } from "../helpers/string";
|
||||||
import RichTextProcessor from "../lib/richtextprocessor";
|
import RichTextProcessor from "../lib/richtextprocessor";
|
||||||
|
|
||||||
@ -56,6 +57,8 @@ class InputField {
|
|||||||
public inputFake: HTMLElement;
|
public inputFake: HTMLElement;
|
||||||
|
|
||||||
//public onLengthChange: (length: number, isOverflow: boolean) => void;
|
//public onLengthChange: (length: number, isOverflow: boolean) => void;
|
||||||
|
private wasInputFakeHeight: number;
|
||||||
|
private showScrollDebounced: () => void;
|
||||||
|
|
||||||
constructor(private options: {
|
constructor(private options: {
|
||||||
placeholder?: string,
|
placeholder?: string,
|
||||||
@ -111,7 +114,9 @@ class InputField {
|
|||||||
observer.observe(input, {characterData: true, childList: true, subtree: true});
|
observer.observe(input, {characterData: true, childList: true, subtree: true});
|
||||||
|
|
||||||
if(options.animate) {
|
if(options.animate) {
|
||||||
input.classList.add('scrollable', 'scrollable-y')
|
input.classList.add('scrollable', 'scrollable-y');
|
||||||
|
this.wasInputFakeHeight = 0;
|
||||||
|
this.showScrollDebounced = debounce(() => this.input.classList.remove('no-scrollbar'), 150, false, true);
|
||||||
this.inputFake = document.createElement('div');
|
this.inputFake = document.createElement('div');
|
||||||
this.inputFake.setAttribute('contenteditable', 'true');
|
this.inputFake.setAttribute('contenteditable', 'true');
|
||||||
this.inputFake.className = input.className + ' input-field-input-fake';
|
this.inputFake.className = input.className + ' input-field-input-fake';
|
||||||
@ -158,6 +163,12 @@ class InputField {
|
|||||||
|
|
||||||
public onFakeInput() {
|
public onFakeInput() {
|
||||||
const scrollHeight = this.inputFake.scrollHeight;
|
const scrollHeight = this.inputFake.scrollHeight;
|
||||||
|
if(this.wasInputFakeHeight && this.wasInputFakeHeight !== scrollHeight) {
|
||||||
|
this.input.classList.add('no-scrollbar'); // ! в сафари может вообще не появиться скролл после анимации, так как ему нужен полный reflow блока с overflow.
|
||||||
|
this.showScrollDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.wasInputFakeHeight = scrollHeight;
|
||||||
this.input.style.height = scrollHeight ? scrollHeight + 'px' : '';
|
this.input.style.height = scrollHeight ? scrollHeight + 'px' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,21 @@ html:not(.is-safari):not(.is-ios) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.scrollable-x::-webkit-scrollbar {
|
.scrollable-x::-webkit-scrollbar,
|
||||||
|
.no-scrollbar::-webkit-scrollbar {
|
||||||
display: none; // for safari iOS
|
display: none; // for safari iOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* .no-scrollbar::-webkit-scrollbar {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-scrollbar::-webkit-scrollbar-thumb {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
} */
|
||||||
|
|
||||||
.scrollable {
|
.scrollable {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user