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
38 changes: 38 additions & 0 deletions playwright/e2e/mobile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,41 @@ 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: 240, 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.getMenu('Remain').click()
// Insert link toggles with the link mark, so depending on the version of
// @nextcloud/vue it is rendered as a checkbox
await editor
.getMenuItem('Insert link')
.or(editor.el.getByRole('menuitemcheckbox', { name: 'Insert link' }))
.click()
await expect(editor.getMenuItem('Link to website')).toBeVisible()
})
})
2 changes: 1 addition & 1 deletion src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template v-for="child in children">
<NcActionSeparator
v-if="child.isSeparator"
:key="`child-${child.key}`" />
:key="`separator-${child.key}`" />
<ActionListItem
v-else
:key="`child-${child.key}`"
Expand Down
28 changes: 16 additions & 12 deletions src/components/Menu/BaseActionEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,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')
} else {
Expand All @@ -104,12 +99,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
44 changes: 40 additions & 4 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default {
? [...this.menuEntries]
: [...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 @@ -156,10 +157,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() {
// only entries from `visibleEntryKeys but in original order
Expand All @@ -174,22 +180,36 @@ 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 @@ -237,6 +257,22 @@ export default {
hideHelp() {
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()
// The ref is in no order, so look up the entry by its key
const entry = this.$refs.menuEntries?.find(
(component) => component.actionEntry.key === key,
)
entry?.openMenu()
},

t,
},
}
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 @@ -48,7 +48,6 @@ import { emit } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import { t } from '@nextcloud/l10n'
import { type AnyCommands, type Editor } from '@tiptap/core'
import { isMobileDevice } from '../../helpers/isMobileDevice.js'
import { MODIFIERS } from './keys.js'

type ClickContext = {
Expand Down Expand Up @@ -521,10 +520,7 @@ export const getMenuEntries = (isRichWorkspace: boolean): MenuEntry[] => {
component: ActionAttachmentUpload,
priority: 5,
},
]

if (!isMobileDevice) {
menuEntries.push({
{
key: 'emoji-picker',
label: t('text', 'Insert emoji'),
icon: Emoticon,
Expand All @@ -534,8 +530,8 @@ export const getMenuEntries = (isRichWorkspace: boolean): MenuEntry[] => {
return command.emoji(emojiObject)
},
priority: 6,
})
}
},
]

return menuEntries
}
Loading