fix: editor content being hidden under keyboard on mobile (#1410)

This commit is contained in:
Aman Harwara
2022-08-25 15:01:44 +05:30
committed by GitHub
parent c336f9de18
commit 520b3add0f
18 changed files with 124 additions and 72 deletions

View File

@@ -0,0 +1,30 @@
import { classNames } from '@/Utils/ConcatenateClassNames'
import { ComponentPropsWithoutRef, ForwardedRef, forwardRef } from 'react'
// Based on: https://css-tricks.com/auto-growing-inputs-textareas/#aa-other-ideas
const AutoresizingNoteViewTextarea = forwardRef(
({ value, ...textareaProps }: ComponentPropsWithoutRef<'textarea'>, ref: ForwardedRef<HTMLTextAreaElement>) => {
return (
<div className="relative inline-grid min-h-[75vh] w-full grid-rows-1 items-stretch md:block md:flex-grow">
<pre
id="textarea-mobile-resizer"
className={classNames(
'editable font-editor break-word whitespace-pre-wrap',
'invisible [grid-area:1_/_1] md:hidden',
)}
aria-hidden
>
{value}{' '}
</pre>
<textarea
value={value}
className="editable font-editor [grid-area:1_/_1] md:h-full md:min-h-0"
{...textareaProps}
ref={ref}
></textarea>
</div>
)
},
)
export default AutoresizingNoteViewTextarea

View File

@@ -37,6 +37,7 @@ import { reloadFont } from './FontFunctions'
import { NoteViewProps } from './NoteViewProps'
import IndicatorCircle from '../IndicatorCircle/IndicatorCircle'
import { classNames } from '@/Utils/ConcatenateClassNames'
import AutoresizingNoteViewTextarea from './AutoresizingTextarea'
const MINIMUM_STATUS_DURATION = 400
const TEXTAREA_DEBOUNCE = 100
@@ -889,7 +890,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
return (
<div aria-label="Note" className="section editor sn-component">
<div className="flex flex-grow flex-col">
<div className="flex-grow flex-col md:flex">
{this.state.noteLocked && (
<EditingDisabledBanner
onMouseLeave={() => {
@@ -1021,9 +1022,8 @@ class NoteView extends PureComponent<NoteViewProps, State> {
)}
{this.state.editorStateDidLoad && !this.state.editorComponentViewer && !this.state.textareaUnloading && (
<textarea
<AutoresizingNoteViewTextarea
autoComplete="off"
className="editable font-editor"
dir="auto"
id={ElementIds.NoteTextEditor}
onChange={this.onTextAreaChange}
@@ -1032,7 +1032,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
onFocus={this.onContentFocus}
spellCheck={this.state.spellcheck}
ref={(ref) => ref && this.onSystemEditorLoad(ref)}
></textarea>
/>
)}
{this.state.marginResizersEnabled && this.editorContentRef.current ? (