feat: Changed floating toolbar in Super to be always visible above keyboard on mobile (#2188)
This commit is contained in:
@@ -13,6 +13,21 @@
|
|||||||
will-change: transform;
|
will-change: transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.floating-text-format-popup {
|
||||||
|
top: auto;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
overflow-x: scroll;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.floating-text-format-popup::-webkit-scrollbar {
|
||||||
|
width: 0px;
|
||||||
|
height: 0px;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.floating-text-format-popup button.popup-item {
|
.floating-text-format-popup button.popup-item {
|
||||||
border: 0;
|
border: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ function TextFormatFloatingToolbar({
|
|||||||
|
|
||||||
function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLElement): JSX.Element | null {
|
function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLElement): JSX.Element | null {
|
||||||
const [activeEditor, setActiveEditor] = useState(editor)
|
const [activeEditor, setActiveEditor] = useState(editor)
|
||||||
const [isText, setIsText] = useState(false)
|
const [isVisible, setIsVisible] = useState(false)
|
||||||
const [isLink, setIsLink] = useState(false)
|
const [isLink, setIsLink] = useState(false)
|
||||||
const [isBold, setIsBold] = useState(false)
|
const [isBold, setIsBold] = useState(false)
|
||||||
const [isItalic, setIsItalic] = useState(false)
|
const [isItalic, setIsItalic] = useState(false)
|
||||||
@@ -337,11 +337,17 @@ function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLEle
|
|||||||
const nativeSelection = window.getSelection()
|
const nativeSelection = window.getSelection()
|
||||||
const rootElement = editor.getRootElement()
|
const rootElement = editor.getRootElement()
|
||||||
|
|
||||||
|
const isMobile = window.matchMedia('(max-width: 768px)').matches
|
||||||
|
|
||||||
if (
|
if (
|
||||||
nativeSelection !== null &&
|
nativeSelection !== null &&
|
||||||
(!$isRangeSelection(selection) || rootElement === null || !rootElement.contains(nativeSelection.anchorNode))
|
(!$isRangeSelection(selection) || rootElement === null || !rootElement.contains(nativeSelection.anchorNode))
|
||||||
) {
|
) {
|
||||||
setIsText(false)
|
if (isMobile) {
|
||||||
|
setIsVisible(true)
|
||||||
|
} else {
|
||||||
|
setIsVisible(false)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,9 +404,11 @@ function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLEle
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$isCodeHighlightNode(selection.anchor.getNode()) && selection.getTextContent() !== '') {
|
if (!$isCodeHighlightNode(selection.anchor.getNode()) && selection.getTextContent() !== '') {
|
||||||
setIsText($isTextNode(node))
|
setIsVisible($isTextNode(node))
|
||||||
|
} else if (isMobile) {
|
||||||
|
setIsVisible(true)
|
||||||
} else {
|
} else {
|
||||||
setIsText(false)
|
setIsVisible(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, [editor, activeEditor])
|
}, [editor, activeEditor])
|
||||||
@@ -424,13 +432,13 @@ function useFloatingTextFormatToolbar(editor: LexicalEditor, anchorElem: HTMLEle
|
|||||||
}),
|
}),
|
||||||
editor.registerRootListener(() => {
|
editor.registerRootListener(() => {
|
||||||
if (editor.getRootElement() === null) {
|
if (editor.getRootElement() === null) {
|
||||||
setIsText(false)
|
setIsVisible(false)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}, [editor, updatePopup])
|
}, [editor, updatePopup])
|
||||||
|
|
||||||
if (!isText || isLink) {
|
if (!isVisible || isLink) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ export function setFloatingElemPosition(
|
|||||||
): void {
|
): void {
|
||||||
const scrollerElem = anchorElem.parentElement
|
const scrollerElem = anchorElem.parentElement
|
||||||
|
|
||||||
|
const isMobileScreen = window.innerWidth < 768
|
||||||
|
|
||||||
|
if (isMobileScreen) {
|
||||||
|
floatingElem.style.opacity = '1'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (targetRect === null || !scrollerElem) {
|
if (targetRect === null || !scrollerElem) {
|
||||||
floatingElem.style.opacity = '0'
|
floatingElem.style.opacity = '0'
|
||||||
floatingElem.style.transform = 'translate(-10000px, -10000px)'
|
floatingElem.style.transform = 'translate(-10000px, -10000px)'
|
||||||
|
|||||||
Reference in New Issue
Block a user