Skip to content

Commit

Permalink
fix(mobile): dropdowns for editing toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jan 5, 2025
1 parent 955542a commit c6e4d48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
31 changes: 30 additions & 1 deletion src/public/app/widgets/ribbon_widgets/classic_editor_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ const TPL = `\
left: 0;
bottom: 0;
right: 0;
height: 10vh;
overflow-x: auto;
z-index: 500;
user-select: none;
}
body.mobile .classic-toolbar-widget.dropdown-active {
height: 50vh;
}
body.mobile .classic-toolbar-widget .ck.ck-toolbar {
position: absolute;
background-color: var(--main-background-color);
}
body.mobile .classic-toolbar-widget .ck.ck-dropdown__panel {
bottom: 100% !important;
top: unset !important;
}
</style>
`;

Expand All @@ -56,6 +64,12 @@ const TPL = `\
* The ribbon item is active by default for text notes, as long as they are not in read-only mode.
*/
export default class ClassicEditorToolbar extends NoteContextAwareWidget {

constructor() {
super();
this.observer = new MutationObserver((e) => this.#onDropdownStateChanged(e));
}

get name() {
return "classicEditor";
}
Expand All @@ -69,11 +83,26 @@ export default class ClassicEditorToolbar extends NoteContextAwareWidget {
this.contentSized();

if (utils.isMobile()) {
// The virtual keyboard obscures the editing toolbar so we have to reposition by calculating the height of the keyboard.
window.visualViewport.addEventListener("resize", () => this.#adjustPosition());
window.addEventListener("scroll", () => this.#adjustPosition());

// Observe when a dropdown is expanded to apply a style that allows the dropdown to be visible, since we can't have the element both visible and the toolbar scrollable.
this.observer.disconnect();
this.observer.observe(this.$widget[0], {
attributeFilter: [ "aria-expanded" ],
subtree: true
});
}
}

#onDropdownStateChanged(e) {
const dropdownActive = e
.map((e) => e.target.ariaExpanded === "true")
.reduce((acc, e) => acc && e);
this.$widget[0].classList.toggle("dropdown-active", dropdownActive);
}

#adjustPosition() {
const bottom = window.innerHeight - window.visualViewport.height;
this.$widget.css("bottom", `${bottom}px`);
Expand Down
13 changes: 1 addition & 12 deletions src/public/app/widgets/type_widgets/editable_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {

// Hide the formatting toolbar
this.$editor.on("focusout", (e) => {
setTimeout(() => {
if (document.activeElement === this.$editor[0]) {
// Editor has been refocused.
return;
}

if ($classicToolbarWidget[0].contains(document.activeElement)) {
return;
}

$classicToolbarWidget.removeClass("visible");
}, 100);
this.$editor[0].focus();
});
}
}
Expand Down

0 comments on commit c6e4d48

Please sign in to comment.