mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Desktop: Accessibility: Fix context menu button doesn't open the note list context menu (regression) (#11175)
This commit is contained in:
parent
349fa426ea
commit
0ea61f26eb
@ -1,5 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useMemo, useRef, useEffect } from 'react';
|
import { useMemo, useRef, useEffect, useCallback } from 'react';
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import BaseModel, { ModelType } from '@joplin/lib/BaseModel';
|
import BaseModel, { ModelType } from '@joplin/lib/BaseModel';
|
||||||
import { Props } from './utils/types';
|
import { Props } from './utils/types';
|
||||||
@ -275,6 +275,12 @@ const NoteList = (props: Props) => {
|
|||||||
return output;
|
return output;
|
||||||
}, [listRenderer.flow]);
|
}, [listRenderer.flow]);
|
||||||
|
|
||||||
|
const onContainerContextMenu = useCallback((event: React.MouseEvent) => {
|
||||||
|
const isFromKeyboard = event.button === -1;
|
||||||
|
if (event.isDefaultPrevented() || !isFromKeyboard) return;
|
||||||
|
onItemContextMenu({ itemId: activeNoteId });
|
||||||
|
}, [onItemContextMenu, activeNoteId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
role='listbox'
|
role='listbox'
|
||||||
@ -293,6 +299,7 @@ const NoteList = (props: Props) => {
|
|||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onKeyUp={onKeyUp}
|
onKeyUp={onKeyUp}
|
||||||
onDrop={onDrop}
|
onDrop={onDrop}
|
||||||
|
onContextMenu={onContainerContextMenu}
|
||||||
>
|
>
|
||||||
{renderEmptyList()}
|
{renderEmptyList()}
|
||||||
{renderFiller('top', topFillerStyle)}
|
{renderFiller('top', topFillerStyle)}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import * as React from 'react';
|
||||||
import Folder from '@joplin/lib/models/Folder';
|
import Folder from '@joplin/lib/models/Folder';
|
||||||
import { NoteEntity } from '@joplin/lib/services/database/types';
|
import { NoteEntity } from '@joplin/lib/services/database/types';
|
||||||
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
|
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
|
||||||
@ -6,6 +7,13 @@ import { Dispatch } from 'redux';
|
|||||||
import bridge from '../../../services/bridge';
|
import bridge from '../../../services/bridge';
|
||||||
import NoteListUtils from '../../utils/NoteListUtils';
|
import NoteListUtils from '../../utils/NoteListUtils';
|
||||||
|
|
||||||
|
interface CustomContextMenuEvent {
|
||||||
|
itemId: string;
|
||||||
|
currentTarget?: undefined;
|
||||||
|
preventDefault?: undefined;
|
||||||
|
}
|
||||||
|
type ContextMenuEvent = React.MouseEvent|CustomContextMenuEvent;
|
||||||
|
|
||||||
const useOnContextMenu = (
|
const useOnContextMenu = (
|
||||||
selectedNoteIds: string[],
|
selectedNoteIds: string[],
|
||||||
selectedFolderId: string,
|
selectedFolderId: string,
|
||||||
@ -15,10 +23,14 @@ const useOnContextMenu = (
|
|||||||
plugins: PluginStates,
|
plugins: PluginStates,
|
||||||
customCss: string,
|
customCss: string,
|
||||||
) => {
|
) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
return useCallback((event: ContextMenuEvent) => {
|
||||||
return useCallback((event: any) => {
|
let currentNoteId = event.currentTarget?.getAttribute('data-id');
|
||||||
const currentNoteId = event.currentTarget.getAttribute('data-id');
|
if ('itemId' in event) {
|
||||||
|
currentNoteId = event.itemId;
|
||||||
|
}
|
||||||
|
|
||||||
if (!currentNoteId) return;
|
if (!currentNoteId) return;
|
||||||
|
event.preventDefault?.();
|
||||||
|
|
||||||
let noteIds = [];
|
let noteIds = [];
|
||||||
if (selectedNoteIds.indexOf(currentNoteId) < 0) {
|
if (selectedNoteIds.indexOf(currentNoteId) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user