Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions playwright/e2e/mobile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,33 @@ test('Formatting help', async ({ editor }) => {
await editor.formattingHelp.getByLabel('Close').click()
await expect(editor.formattingHelp).not.toBeVisible()
})

test.describe('Actions with their own menu in remaining actions', () => {
test.beforeEach(async ({ page }) => {
// Narrow enough to move link, attachment and emoji into the remaining actions
await page.setViewportSize({ width: 280, height: 640 })
})

test('Insert emoji', async ({ editor }) => {
await editor.clickMenu('Remain', 'Insert emoji')
const picker = editor.el.getByRole('dialog', { name: 'Emoji picker' })
await expect(picker).toBeVisible()
const search = picker.getByRole('textbox', { name: 'Search' })
await search.fill('cat')
await expect(picker.getByLabel('🐱, cat')).toHaveClass(/emoji-mart-emoji-selected/)
await search.press('Enter')
await expect(editor.content).toContainText('🐱')
await expect(editor.content).not.toContainText('undefined')
})

test('Insert attachment', async ({ editor }) => {
await editor.clickMenu('Remain', 'Insert attachment')
await expect(editor.getMenuItem('Upload from computer')).toBeVisible()
await expect(editor.getMenuItem('Insert from Files')).toBeVisible()
})

test('Insert link', async ({ editor }) => {
await editor.clickMenu('Remain', 'Insert link')
await expect(editor.getMenuItem('Link to website')).toBeVisible()
})
})
5 changes: 3 additions & 2 deletions src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
<template #icon>
<component :is="icon" :key="iconKey" />
</template>
<template v-for="child in children" :key="`child-${child.key}`">
<NcActionSeparator v-if="child.isSeparator" />
<template v-for="child in children">
<NcActionSeparator v-if="child.isSeparator" :key="`separator-${child.key}`" />
<ActionListItem
v-else
:key="`child-${child.key}`"
:active="currentChild?.key === child.key"
isItem
:actionEntry="child"
Expand Down
27 changes: 16 additions & 11 deletions src/components/Menu/BaseActionEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ const BaseActionEntry = {
this.$emit('disabled', this.state.disabled)
},
setTabIndexOnButton() {
/** @type {HTMLButtonElement} */
const button
= this.$el.tagName.toLowerCase() === 'button'
? this.$el
: this.$el.querySelector('button')
const button = this.getButton()

if (this.canBeFocussed === null) {
button.removeAttribute('tabindex')
Expand All @@ -102,12 +98,21 @@ const BaseActionEntry = {
* Focus the inner button of this action
*/
focusButton() {
/** @type {HTMLButtonElement} */
const button
= this.$el.tagName.toLowerCase() === 'button'
? this.$el
: this.$el.querySelector('button')
button.focus()
this.getButton().focus()
},
/**
* Open the menu of this action, e.g. when triggered from the remaining actions
*/
openMenu() {
this.getButton().click()
},
/**
* @return {HTMLButtonElement} The inner button of this action
*/
getButton() {
return this.$el.tagName.toLowerCase() === 'button'
? this.$el
: this.$el.querySelector('button')
},
},
}
Expand Down
30 changes: 26 additions & 4 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default {
: [...this.menuEntries, ...this.assistantMenuEntries]
).filter((entry) => !!entry),

forcedEntryKey: null,
randomID: `menu-bar-${Math.ceil(Math.random() * 10000 + 500).toString(16)}`,
displayHelp: false,
isReady: false,
Expand All @@ -166,10 +167,15 @@ export default {
computed: {
visibleEntryKeys() {
// if entry has no priority, we assume it always will be visible (priority: 0)
return this.entries
const keys = this.entries
.toSorted((a, b) => (a.priority ?? 0) - (b.priority ?? 0))
.map((e) => e.key)
.slice(0, this.iconsLimit)
if (this.forcedEntryKey && !keys.includes(this.forcedEntryKey)) {
// Make room for the entry that was opened from the remaining actions
keys.splice(-1, 1, this.forcedEntryKey)
}
return keys
},

visibleEntries() {
Expand All @@ -186,22 +192,26 @@ export default {
})
const entries = remainingEntries.reduce((acc, entry, index) => {
// If entry has children, merge them into list. Otherwise keep entry itself.
const children = entry.children ?? [entry]
// Entries rendered by their own component cannot run inside the list,
// so they are moved into the menu bar and opened there.
const children = entry.children ?? [entry.component
? { ...entry, click: () => this.openRemainingEntry(entry.key) }
: entry]
// If this block has menu entries, it should be separated for better visibility and a11y (menu item radio grouping)
if (children.length > 1) {
const hasPreviousItem = acc.length && !acc.at(-1).isSeparator
const separatorBefore = hasPreviousItem
? [
{
key: `separator-before-${entry.id}`,
key: `separator-before-${entry.key}`,
isSeparator: true,
},
]
: []

const hasNextItem = index !== remainingEntries.length - 1
const separatorAfter = hasNextItem
? [{ key: `separator-after-${entry.id}`, isSeparator: true }]
? [{ key: `separator-after-${entry.key}`, isSeparator: true }]
: []

return [
Expand Down Expand Up @@ -258,6 +268,18 @@ export default {
this.displayHelp = false
},

/**
* Show an entry from the remaining actions in the menu bar and open it
*
* @param {string} key The key of the menu entry
*/
async openRemainingEntry(key) {
this.forcedEntryKey = key
await this.$nextTick()
const index = this.visibleEntries.findIndex((entry) => entry.key === key)
this.menuEntryRefs[index]?.openMenu()
},

collectMenuEntryRef(el, index) {
if (el) {
this.menuEntryRefs[index] = el
Expand Down
10 changes: 3 additions & 7 deletions src/components/Menu/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import ActionAttachmentUpload from './ActionAttachmentUpload.vue'
import ActionInsertLink from './ActionInsertLink.vue'
import AssistantAction from './AssistantAction.vue'
import EmojiPickerAction from './EmojiPickerAction.vue'
import { isMobileDevice } from '../../helpers/isMobileDevice.js'
import {
Asterisk,
CodeBrackets,
Expand Down Expand Up @@ -614,10 +613,7 @@ export function getMenuEntries(isRichWorkspace: boolean, annotationsHidden?: Ref
component: markRaw(ActionAttachmentUpload),
priority: 6,
},
]

if (!isMobileDevice) {
menuEntries.push({
{
key: 'emoji-picker',
label: t('text', 'Insert emoji'),
icon: Emoticon,
Expand All @@ -627,8 +623,8 @@ export function getMenuEntries(isRichWorkspace: boolean, annotationsHidden?: Ref
return command.emoji(emojiObject)
},
priority: 7,
})
}
},
]

return menuEntries
}
Loading