From 5f80f2e89c8c44655d600a363eb986c887a994c9 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 14:55:26 +1300 Subject: [PATCH 01/12] New version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bdeb07..9908c7b 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ ], "type": "module", "types": "dist/index.d.ts", - "version": "0.20261204.1", + "version": "0.20261204.2", "exports": { ".": { "types": "./dist/index.d.ts", From 423ad17303b3d98196d3687c461b5d0ace17ce53 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 14:52:54 +1300 Subject: [PATCH 02/12] Added support for disabled context menu actions. --- README.md | 7 +-- demo/App.vue | 24 +++++++-- src/widgets/ContextMenuWidget.vue | 85 +++++++++++++++++++++++-------- 3 files changed, 88 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f679a8c..9548860 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ The component is the default export of `@opencor/plot`, and is also exported as | `PlotImageExportEvent` | `{ action: 'copy' \| 'export'; format: 'jpeg' \| 'png' \| 'svg' \| 'webp'; success: boolean }` | The payload of the [`imageExport`](#events) event: whether the plot was copied to the clipboard (always as PNG) or exported to an image file, in which format, and whether it worked. | | `PlotContextMenuEvent` | `{ clientX: number; clientY: number; usingKeyboard: boolean; items: ContextMenuItem[] }` | The payload of the [`contextMenu`](#events) event: where the context menu was requested (in client coordinates), whether it was requested using the keyboard (in which case the custom menu should take the keyboard focus), and the items that our context menu would have shown. These items reflect the plot as it was when the context menu was requested and don't get updated if the data changes while the custom context menu is shown, but their commands always act on the plot as it is when they are chosen. | | `ContextMenuItem` | `ContextMenuAction \| ContextMenuSeparator \| ContextMenuHeader` | An item of a context menu. | -| `ContextMenuAction` | `{ id?: string; label: string; icon?: IconName; checked?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `id` (so that it can be found, see [Context menu items](#context-menu-items)), its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), the `command` to call when it is chosen, and its submenu `items`, if any. | +| `ContextMenuAction` | `{ id?: string; label: string; icon?: IconName; checked?: boolean; disabled?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `id` (so that it can be found, see [Context menu items](#context-menu-items)), its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), whether it is disabled (i.e. greyed out, can't be chosen, its submenu, if any, can't be opened, and it is skipped when moving through the menu with the keyboard, although it still shows whether it is checked), the `command` to call when it is chosen, and its submenu `items`, if any. | | `ContextMenuSeparator` | `{ separator: true }` | A separator. | | `ContextMenuHeader` | `{ header: string }` | A header that can't be chosen, e.g., the full name of a trace when the context menu is requested from its legend item. It can contain a little HTML (see [Data](#data)). | | `IconName` | `'angle-right' \| 'arrows-h' \| 'arrows-v' \| 'chart-line' \| 'check' \| 'copy' \| 'download' \| 'eye' \| 'image' \| 'list' \| 'pencil' \| 'refresh' \| 'search-minus' \| 'search-plus'` | The name of an icon (from [PrimeIcons](https://primevue.org/icons/)). | @@ -313,7 +313,7 @@ To draw traces without our level of detail, use `:levelOfDetail="false"`. Our pa | `imageExport` | [`PlotImageExportEvent`](#types) | The plot has been copied to the clipboard or exported to an image (or has failed to be), so that the user can be told about it. | | `rangesUpdated` | [`PlotRanges`](#types) | The range of an axis has changed, or whether it is zoomed has. It is emitted at most once per frame, including while the plot is being zoomed, panned, or animated, and while its data gets updated. | | `update:showLegend` | `boolean` | The user has shown or hidden the legend using the context menu, so that the [`showLegend`](#props) prop can say the same (e.g., using `v-model:showLegend`). | -| `contextMenu` | [`PlotContextMenuEvent`](#types) | Only with [`customContextMenu`](#props): the context menu was requested at `clientX`/`clientY`, with the `items` that our context menu would have shown. If `usingKeyboard` is true, the custom menu should take the keyboard focus. The custom menu should call the `command` of the chosen item while handling the click (or tap, or key press) that chose it, and it shouldn't move the keyboard focus afterwards (calling [`contextMenuHidden()`](#methods) instead), since some commands (e.g., to edit the range of an axis) give the keyboard focus to an editor that closes when it loses it, and iOS only shows its virtual keyboard for such an editor while handling a user interaction. If it calls that `command` while handling a key press (e.g., Enter or Space), it should also prevent that key's default action (using `preventDefault()`), since the key would otherwise also be typed into such an editor, replacing its selected value. | +| `contextMenu` | [`PlotContextMenuEvent`](#types) | Only with [`customContextMenu`](#props): the context menu was requested at `clientX`/`clientY`, with the `items` that our context menu would have shown. The custom menu should show the actions that are `disabled` (see [`ContextMenuAction`](#types)) as such, and not let them (or their submenu items) be chosen. If `usingKeyboard` is true, the custom menu should take the keyboard focus. The custom menu should call the `command` of the chosen item while handling the click (or tap, or key press) that chose it, and it shouldn't move the keyboard focus afterwards (calling [`contextMenuHidden()`](#methods) instead), since some commands (e.g., to edit the range of an axis) give the keyboard focus to an editor that closes when it loses it, and iOS only shows its virtual keyboard for such an editor while handling a user interaction. If it calls that `command` while handling a key press (e.g., Enter or Space), it should also prevent that key's default action (using `preventDefault()`), since the key would otherwise also be typed into such an editor, replacing its selected value. | ### Methods @@ -347,7 +347,7 @@ Copied and exported images always use the light colours (white background, dark ### Context menu items -The items of the context menu can be customised using the [`contextMenuItems`](#props) prop, e.g., to add an item that lets the user choose whether the X axes of some plots are synchronised, at the end of the submenu of the X axis (and separated from its other items): +The items of the context menu can be customised using the [`contextMenuItems`](#props) prop, e.g., to add an item that lets the user choose whether the X axes of some plots are synchronised, at the end of the submenu of the X axis (and separated from its other items), and which is disabled when there is no other plot to synchronise with: ```ts const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { @@ -360,6 +360,7 @@ const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { { label: 'Linked', checked: linkedXAxes.value, + disabled: nbOfPlots.value < 2, command: () => { linkedXAxes.value = !linkedXAxes.value; } diff --git a/demo/App.vue b/demo/App.vue index 9fcbf41..199a1cc 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -262,7 +262,7 @@
  • {{ item.label }}
    - +
  • @@ -916,7 +916,8 @@ const ALIGN_GROUP = Symbol('demo'); const SYNC_GROUP = Symbol('demo'); // Customise the context menu of our instances, so that the user can choose whether their X and/or Y axes are -// synchronised from there too, at the end of the submenu of each axis (and separated from its other items). +// synchronised from there too, at the end of the submenu of each axis (and separated from its other items). That item +// is disabled when there is only one instance, since there is then no other instance to synchronise with. const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { const linkedAxes = { xAxis: linkedXAxes, yAxis: linkedYAxes }; @@ -931,6 +932,7 @@ const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { { label: 'Linked', checked: linked.value, + disabled: nbOfInstances.value < 2, command: () => { linked.value = !linked.value; } @@ -1673,6 +1675,7 @@ const sectionBindings = (name: string): { open: boolean; onToggle: (event: Event interface CustomMenuItem { label: string; header?: boolean; + disabled?: boolean; command?: () => void; } @@ -1692,7 +1695,9 @@ const headerLabel = (header: string): string => { return body.textContent ?? ''; }; -const flattenedItems = (items: ContextMenuItem[], prefix: string = ''): CustomMenuItem[] => { +const flattenedItems = (items: ContextMenuItem[], prefix: string = '', disabled: boolean = false): CustomMenuItem[] => { + // Note: the items of the submenu of a disabled action are also disabled, since that submenu can't be opened. + return items.flatMap((item: ContextMenuItem): CustomMenuItem[] => { if ('separator' in item) { return [{ label: '' }]; @@ -1704,7 +1709,11 @@ const flattenedItems = (items: ContextMenuItem[], prefix: string = ''): CustomMe const label = `${prefix}${item.label}${item.checked ? ' ✓' : ''}`; - return item.items ? flattenedItems(item.items, `${label} › `) : [{ label, command: item.command }]; + const itemDisabled = disabled || !!item.disabled; + + return item.items + ? flattenedItems(item.items, `${label} › `, itemDisabled) + : [{ label, disabled: itemDisabled, command: item.command }]; }); }; @@ -2023,7 +2032,12 @@ const onWindowPointerDown = (event: PointerEvent): void => { cursor: pointer; } - .demo-custom-menu button:hover, + .demo-custom-menu button:disabled { + opacity: 0.6; + cursor: default; + } + + .demo-custom-menu button:enabled:hover, .demo-custom-menu button:focus-visible { background-color: var(--demo-border); } diff --git a/src/widgets/ContextMenuWidget.vue b/src/widgets/ContextMenuWidget.vue index 54cca5a..552f458 100644 --- a/src/widgets/ContextMenuWidget.vue +++ b/src/widgets/ContextMenuWidget.vue @@ -24,10 +24,12 @@
  • {{ item.label }} -
    +
  • @@ -1675,6 +1675,7 @@ const sectionBindings = (name: string): { open: boolean; onToggle: (event: Event interface CustomMenuItem { label: string; header?: boolean; + separator?: boolean; disabled?: boolean; command?: () => void; } @@ -1696,11 +1697,13 @@ const headerLabel = (header: string): string => { }; const flattenedItems = (items: ContextMenuItem[], prefix: string = '', disabled: boolean = false): CustomMenuItem[] => { - // Note: the items of the submenu of a disabled action are also disabled, since that submenu can't be opened. + // Note #1: the items of the submenu of a disabled action are also disabled, since that submenu can't be opened. + // Note #2: a separator is flagged as such rather than being an item without a command, since an action may have no + // command (e.g., a disabled action that is only there to give some information). return items.flatMap((item: ContextMenuItem): CustomMenuItem[] => { if ('separator' in item) { - return [{ label: '' }]; + return [{ label: '', separator: true }]; } if ('header' in item) { @@ -1743,10 +1746,10 @@ const hideCustomMenu = (): void => { plotRefs[instance]?.contextMenuHidden(); }; -const onCustomMenuItemClick = (command: () => void): void => { +const onCustomMenuItemClick = (command: (() => void) | undefined): void => { hideCustomMenu(); - command(); + command?.(); }; const onWindowPointerDown = (event: PointerEvent): void => { From 267a7fa0cf8622b6cc6d0b7078b77337cc2b023a Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 15:10:56 +1300 Subject: [PATCH 05/12] Made disabled context menu actions focusable. --- README.md | 2 +- src/widgets/ContextMenuWidget.vue | 59 ++++++++++++------------------- 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 9548860..5456c10 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ The component is the default export of `@opencor/plot`, and is also exported as | `PlotImageExportEvent` | `{ action: 'copy' \| 'export'; format: 'jpeg' \| 'png' \| 'svg' \| 'webp'; success: boolean }` | The payload of the [`imageExport`](#events) event: whether the plot was copied to the clipboard (always as PNG) or exported to an image file, in which format, and whether it worked. | | `PlotContextMenuEvent` | `{ clientX: number; clientY: number; usingKeyboard: boolean; items: ContextMenuItem[] }` | The payload of the [`contextMenu`](#events) event: where the context menu was requested (in client coordinates), whether it was requested using the keyboard (in which case the custom menu should take the keyboard focus), and the items that our context menu would have shown. These items reflect the plot as it was when the context menu was requested and don't get updated if the data changes while the custom context menu is shown, but their commands always act on the plot as it is when they are chosen. | | `ContextMenuItem` | `ContextMenuAction \| ContextMenuSeparator \| ContextMenuHeader` | An item of a context menu. | -| `ContextMenuAction` | `{ id?: string; label: string; icon?: IconName; checked?: boolean; disabled?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `id` (so that it can be found, see [Context menu items](#context-menu-items)), its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), whether it is disabled (i.e. greyed out, can't be chosen, its submenu, if any, can't be opened, and it is skipped when moving through the menu with the keyboard, although it still shows whether it is checked), the `command` to call when it is chosen, and its submenu `items`, if any. | +| `ContextMenuAction` | `{ id?: string; label: string; icon?: IconName; checked?: boolean; disabled?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `id` (so that it can be found, see [Context menu items](#context-menu-items)), its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), whether it is disabled (i.e. greyed out, can't be chosen, and its submenu, if any, can't be opened, although it can still be focused, so that assistive technologies announce it as disabled, and it still shows whether it is checked), the `command` to call when it is chosen, and its submenu `items`, if any. | | `ContextMenuSeparator` | `{ separator: true }` | A separator. | | `ContextMenuHeader` | `{ header: string }` | A header that can't be chosen, e.g., the full name of a trace when the context menu is requested from its legend item. It can contain a little HTML (see [Data](#data)). | | `IconName` | `'angle-right' \| 'arrows-h' \| 'arrows-v' \| 'chart-line' \| 'check' \| 'copy' \| 'download' \| 'eye' \| 'image' \| 'list' \| 'pencil' \| 'refresh' \| 'search-minus' \| 'search-plus'` | The name of an icon (from [PrimeIcons](https://primevue.org/icons/)). | diff --git a/src/widgets/ContextMenuWidget.vue b/src/widgets/ContextMenuWidget.vue index a3ecd0f..871b637 100644 --- a/src/widgets/ContextMenuWidget.vue +++ b/src/widgets/ContextMenuWidget.vue @@ -73,9 +73,10 @@ import IconWidget from './IconWidget.vue'; // and it wraps rather than makes our context menu wider. A menu can only contain items, groups, and // separators, so a header is hidden from assistive technologies, but it labels its menu (or submenu), so that // it gets announced when its menu gets the keyboard focus. -// Note #3: a disabled action (e.g., one that makes sense in general, but not right now) is greyed out, can't be focused -// or chosen (be it with the mouse or the keyboard), and its submenu, if any, can't be opened. It still shows -// whether it is checked, if it is checkable, and it is described as disabled to assistive technologies. +// Note #3: a disabled action (e.g., one that makes sense in general, but not right now) is greyed out, can't be chosen +// (be it with the mouse or the keyboard), and its submenu, if any, can't be opened. It can still be focused, +// like in the WAI-ARIA menu pattern, so that it gets announced (as disabled) by assistive technologies rather +// than being silently skipped. It also still shows whether it is checked, if it is checkable. // Note #4: only one context menu should be shown at any given time, so we let our other context menus know when we are // about to be shown, and we hide ourselves when another context menu is about to be shown. @@ -193,10 +194,6 @@ const actionAt = (levelIndex: number, index: number): ContextMenuAction | undefi return item && isAction(item) ? item : undefined; }; -const isEnabledAction = (item: ContextMenuItem | undefined): item is ContextMenuAction => { - return !!item && isAction(item) && !item.disabled; -}; - const enabledActionAt = (levelIndex: number, index: number): ContextMenuAction | undefined => { const item = actionAt(levelIndex, index); @@ -303,11 +300,13 @@ const openSubmenu = async (levelIndex: number, index: number, focusFirstItem: bo // Navigation within a level. const nextItemIndex = (level: Level, fromIndex: number, step: 1 | -1): number => { - // Return the index of the next (previous) enabled action, starting from the given index, or the given index if there - // is none (i.e. we don't wrap around, like PrimeVue). + // Return the index of the next (previous) action, be it enabled or disabled (see Note #3 above), starting from the + // given index, or the given index if there is none (i.e. we don't wrap around, like PrimeVue). for (let index = fromIndex + step; index >= 0 && index < level.items.length; index += step) { - if (isEnabledAction(level.items[index])) { + const item = level.items[index]; + + if (item && isAction(item)) { return index; } } @@ -316,12 +315,13 @@ const nextItemIndex = (level: Level, fromIndex: number, step: 1 | -1): number => }; const focusItem = (levelIndex: number, index: number): void => { - // Focus the given item, but only if it is an enabled action. This is notably not the case when nextItemIndex() finds - // no enabled action, in which case it returns the index it started from, which may be -1 or our number of items. + // Focus the given item, but only if it is an action. This is notably not the case when nextItemIndex() finds no + // action, in which case it returns the index it started from, which may be -1 or our number of items. const level = levels.value[levelIndex]; + const item = level?.items[index]; - if (!level || !isEnabledAction(level.items[index])) { + if (!level || !item || !isAction(item)) { return; } @@ -356,7 +356,7 @@ const searchItem = (levelIndex: number, character: string): void => { const index = (level.focusedIndex + i + nbOfItems) % nbOfItems; const item = level.items[index]; - if (isEnabledAction(item) && item.label.toLocaleLowerCase().startsWith(searchString)) { + if (item && isAction(item) && item.label.toLocaleLowerCase().startsWith(searchString)) { focusItem(levelIndex, index); return; @@ -387,21 +387,8 @@ const selectItem = (levelIndex: number, index: number, usingKeyboard: boolean): // Mouse and keyboard handling. const onItemPointerEnter = (levelIndex: number, index: number): void => { - // Hovering a disabled action doesn't focus it, but it unfocuses the focused item of its level and closes the open - // submenu, if any, like hovering another item would (see Note #3 above). - - if (!enabledActionAt(levelIndex, index)) { - const level = levels.value[levelIndex]; - - if (level) { - level.focusedIndex = -1; - } - - closeLevelsAfter(levelIndex); - focusLevel(levelIndex); - - return; - } + // Focus the hovered item, even if it is a disabled action (like using the keyboard would), and open its submenu, if + // any, unless it is a disabled action (see Note #3 above). focusItem(levelIndex, index); focusLevel(levelIndex); @@ -541,8 +528,8 @@ const show = async (event: MouseEvent, usingKeyboard: boolean = false): Promise< // Note: our items may change while our context menu is shown (e.g., the label of an item may depend on some data that // gets updated in the meantime), in which case we update our levels. Our items may get recreated, so we identify // an item by its label, but only if no other item of its level has the same label, both before and after the -// update: the focused item of a level remains focused (even if it has moved) as long as it can be identified and -// is enabled, and so does an open submenu as long as its parent item can be identified, is enabled, and still has +// update: the focused item of a level remains focused (even if it has moved or got disabled) as long as it can be +// identified, and so does an open submenu as long as its parent item can be identified, is enabled, and still has // a submenu. Otherwise, that item is no longer focused (so that choosing the focused item can never run another // action than the one that was focused) and that submenu gets closed. If that submenu had the keyboard focus, // then the focus would be lost (since that submenu's list is gone), so we give it to our last remaining level, so @@ -559,9 +546,8 @@ const actionIndexes = (items: ContextMenuItem[], label: string): number[] => { const matchingActionIndex = (items: ContextMenuItem[], oldItems: ContextMenuItem[], oldIndex: number): number => { // Return the index, in the given items, of the action that has the same label as the action at the given index in the - // given old items, or -1 if there is no such action, if that label is not unique in the given items or old items (in - // which case we can't tell which action is which), or if that action is now disabled (in which case it can't be - // focused and its submenu, if any, can't be open). + // given old items, or -1 if there is no such action or if that label is not unique in the given items or old items + // (in which case we can't tell which action is which). const oldItem = oldItems[oldIndex]; @@ -570,9 +556,8 @@ const matchingActionIndex = (items: ContextMenuItem[], oldItems: ContextMenuItem } const indexes = actionIndexes(items, oldItem.label); - const index = indexes.length === 1 ? (indexes[0] as number) : -1; - return isEnabledAction(items[index]) ? index : -1; + return indexes.length === 1 ? (indexes[0] as number) : -1; }; const updateLevels = async (items: ContextMenuItem[]): Promise => { @@ -602,7 +587,7 @@ const updateLevels = async (items: ContextMenuItem[]): Promise => { const parentItem: ContextMenuItem | undefined = levelItems[parentIndex]; - if (!parentItem || !isAction(parentItem) || !parentItem.items) { + if (!parentItem || !isAction(parentItem) || parentItem.disabled || !parentItem.items) { break; } From 8cab28595375a33f5eea706299ef36f3a3f13ead Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 15:29:12 +1300 Subject: [PATCH 06/12] Fixed undeclared names in the README's context menu example. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5456c10..6f9682f 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,13 @@ Copied and exported images always use the light colours (white background, dark The items of the context menu can be customised using the [`contextMenuItems`](#props) prop, e.g., to add an item that lets the user choose whether the X axes of some plots are synchronised, at the end of the submenu of the X axis (and separated from its other items), and which is disabled when there is no other plot to synchronise with: ```ts +import { type ContextMenuAction, type ContextMenuItem } from '@opencor/plot'; + +import { ref } from 'vue'; + +const nbOfPlots = ref(2); +const linkedXAxes = ref(true); + const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { const xAxisItem = items.find((item): item is ContextMenuAction => 'id' in item && item.id === 'xAxis'); From 56d6f3b31b89b27520603dcf88c5240b3c654a72 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 15:37:00 +1300 Subject: [PATCH 07/12] Made disabled actions focusable in the demo's custom context menu. --- demo/App.vue | 20 +++++++++++++++----- src/common/markerStyleUtils.ts | 6 +++--- src/widgets/PlotWidget.vue | 10 +++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/demo/App.vue b/demo/App.vue index 3f88543..29def54 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -262,7 +262,9 @@
  • {{ item.label }}
    - +
  • @@ -1746,10 +1748,18 @@ const hideCustomMenu = (): void => { plotRefs[instance]?.contextMenuHidden(); }; -const onCustomMenuItemClick = (command: (() => void) | undefined): void => { +const onCustomMenuItemClick = (item: CustomMenuItem): void => { + // Note: a disabled item is flagged using aria-disabled rather than the disabled attribute, so that it can still be + // focused and gets announced (as disabled) by assistive technologies, like in our context menu. This means that + // we must ignore it ourselves and keep our custom context menu open (again, like in our context menu). + + if (item.disabled) { + return; + } + hideCustomMenu(); - command?.(); + item.command?.(); }; const onWindowPointerDown = (event: PointerEvent): void => { @@ -2035,12 +2045,12 @@ const onWindowPointerDown = (event: PointerEvent): void => { cursor: pointer; } - .demo-custom-menu button:disabled { + .demo-custom-menu button[aria-disabled='true'] { opacity: 0.6; cursor: default; } - .demo-custom-menu button:enabled:hover, + .demo-custom-menu button:not([aria-disabled='true']):hover, .demo-custom-menu button:focus-visible { background-color: var(--demo-border); } diff --git a/src/common/markerStyleUtils.ts b/src/common/markerStyleUtils.ts index dc7b086..dd411e1 100644 --- a/src/common/markerStyleUtils.ts +++ b/src/common/markerStyleUtils.ts @@ -123,9 +123,9 @@ export const traceColor = ( }; export const markerPadding = (style: ResolvedMarkerStyle): number => { - // Return the autorange padding (in CSS pixels) for markers of the given style, i.e., like Plotly, more than half their - // size, but at least 3 pixels and, unlike Plotly, at least how far they reach from their point (e.g., because of a - // thick outline, see markerDrawing()), so that they are fully shown. + // Return the autorange padding (in CSS pixels) for markers of the given style, i.e., like Plotly, more than half + // their size, but at least 3 pixels and, unlike Plotly, at least how far they reach from their point (e.g., because + // of a thick outline, see markerDrawing()), so that they are fully shown. return Math.max(style.size / 1.6, 3, markerDrawing(style)?.reach ?? 0); }; diff --git a/src/widgets/PlotWidget.vue b/src/widgets/PlotWidget.vue index df77fe3..817b55a 100644 --- a/src/widgets/PlotWidget.vue +++ b/src/widgets/PlotWidget.vue @@ -3771,8 +3771,8 @@ const setLogAxis = (axisKey: AxisKey, log: boolean, zoomRange: Range | undefined // and replot our data (see plotData()). // Note #1: we forget the last autorange of the axis since it is in the old scale of the axis. // Note #2: we drop the axis from our pending wheel zoom, if any, since it comes from wheel events that happened - // before the axis changed scale, so it would otherwise get applied after it (e.g., if the user makes the axis - // logarithmic right after using the mouse wheel, see dropPendingWheelZoom()). + // before the axis changed scale, so it would otherwise get applied after it (e.g., if the user makes the + // axis logarithmic right after using the mouse wheel, see dropPendingWheelZoom()). finishRangeAnimation(); dropPendingWheelZoom([axisKey]); @@ -5206,9 +5206,9 @@ const onRangeEditorPointerDown = (event: PointerEvent): void => { const dropPendingWheelZoom = (axisKeys: AxisKey[]): void => { // Drop the given axes from our pending wheel zoom, if any, since we are resetting their zoom (be it ourselves or // because a plot with which they are synchronised is resetting it, see resetZoom() and axisSyncer()) or changing - // their scale (see setLogAxis()), and our pending wheel zoom comes from wheel events that happened before that, so - // it would otherwise get applied after it (e.g., if the user presses 0 right after using the mouse wheel). We only - // drop the given axes, so that our pending wheel zoom still gets applied to the other axes, if any. + // their scale (see setLogAxis()), and our pending wheel zoom comes from wheel events that happened before that, so it + // would otherwise get applied after it (e.g., if the user presses 0 right after using the mouse wheel). We only drop + // the given axes, so that our pending wheel zoom still gets applied to the other axes, if any. if (!pendingWheelZoom) { return; From 248ae7c903f56fb89be481d7ee0399e9689c3d38 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 15:40:04 +1300 Subject: [PATCH 08/12] Keep the focus ring of disabled context menu actions fully visible. --- demo/App.vue | 12 ++++++++++-- src/widgets/ContextMenuWidget.vue | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/demo/App.vue b/demo/App.vue index 29def54..1b757d8 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -263,7 +263,7 @@ {{ item.label }}
    @@ -2045,11 +2045,19 @@ const onWindowPointerDown = (event: PointerEvent): void => { cursor: pointer; } + /** + * Note: only the label of a disabled item is greyed out, so that its background and focus ring are as visible as + * those of an enabled item, like in our context menu. + */ + .demo-custom-menu button[aria-disabled='true'] { - opacity: 0.6; cursor: default; } + .demo-custom-menu button[aria-disabled='true'] span { + opacity: 0.6; + } + .demo-custom-menu button:not([aria-disabled='true']):hover, .demo-custom-menu button:focus-visible { background-color: var(--demo-border); diff --git a/src/widgets/ContextMenuWidget.vue b/src/widgets/ContextMenuWidget.vue index 871b637..fdd5007 100644 --- a/src/widgets/ContextMenuWidget.vue +++ b/src/widgets/ContextMenuWidget.vue @@ -729,14 +729,19 @@ defineExpose({ show, hide }); } /** - * Note: a disabled item is greyed out, like in OpenCOR's (i.e. PrimeVue's) context menus. + * Note: a disabled item is greyed out, like in OpenCOR's (i.e. PrimeVue's) context menus. Only its content is greyed + * out, so that its background and focus ring (since it can be focused, see Note #3 at the top of our script) + * are as visible as those of an enabled item. */ .context-menu-item-disabled { - opacity: 0.6; cursor: default; } + .context-menu-item-disabled > * { + opacity: 0.6; + } + /** * Note: with a coarse pointer (e.g., a finger), our items are about 44 pixels high, so that they are easy to touch. */ From 575b9450ee3806d5fd80ec72d7d6d2897113d6b5 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 16:07:52 +1300 Subject: [PATCH 09/12] Clarified that nbOfPlots must be kept up to date in the README's context menu example. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6f9682f..a6d1b7d 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,9 @@ import { type ContextMenuAction, type ContextMenuItem } from '@opencor/plot'; import { ref } from 'vue'; +// The number of plots, which the app must keep up to date (e.g., using a computed from its list of plots), so that our +// item gets disabled when there is no other plot to synchronise with. + const nbOfPlots = ref(2); const linkedXAxes = ref(true); From 7b6ed4580647c3df7ef5da84fc37166f51796609 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 16:11:54 +1300 Subject: [PATCH 10/12] Documented that custom context menus must honour disabled actions. --- src/widgets/PlotWidget.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/PlotWidget.vue b/src/widgets/PlotWidget.vue index 817b55a..8624072 100644 --- a/src/widgets/PlotWidget.vue +++ b/src/widgets/PlotWidget.vue @@ -543,6 +543,9 @@ export interface PlotMemoryUsage { * `customContextMenu` prop is set, so that a custom context menu can be shown instead. Once it has been hidden, call * the `contextMenuHidden()` method, so that the plot can get the keyboard focus back, if needed. * + * The custom context menu should show the actions that are `disabled` (see `ContextMenuAction`) as such, and not let + * them (or their submenu items) be chosen. + * * The custom context menu should call the `command` of the chosen item while handling the user interaction (e.g., a * click) that chose it, and it shouldn't move the keyboard focus afterwards (calling `contextMenuHidden()` instead), * since some commands (e.g., to edit the range of an axis) give the keyboard focus to an editor that gets closed when From 0339fa352fe8907a35182043c35b93ad21d00ebe Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 16:20:44 +1300 Subject: [PATCH 11/12] Made the demo's 'Linked' command ignore stale custom context menus. --- demo/App.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/demo/App.vue b/demo/App.vue index 1b757d8..d1422a6 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -936,6 +936,13 @@ const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { checked: linked.value, disabled: nbOfInstances.value < 2, command: () => { + // Note: our items don't get updated while a custom context menu (see onContextMenu()) is shown, so this item + // may still be chosen after our number of instances has dropped to one, hence we check it again. + + if (nbOfInstances.value < 2) { + return; + } + linked.value = !linked.value; } } From 736d229d767815bd9ab76f809199bfdcdef6c5ed Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 4 Dec 2026 16:22:31 +1300 Subject: [PATCH 12/12] Made the README's 'Linked' command ignore stale custom context menus. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a6d1b7d..181f842 100644 --- a/README.md +++ b/README.md @@ -372,6 +372,13 @@ const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => { checked: linkedXAxes.value, disabled: nbOfPlots.value < 2, command: () => { + // Note: the items don't get updated while a custom context menu (see customContextMenu) is shown, so this item + // may still be chosen after the number of plots has dropped to one, hence we check it again. + + if (nbOfPlots.value < 2) { + return; + } + linkedXAxes.value = !linkedXAxes.value; } }