From 144b0dfdbf837c5feb6644293f4a4edc9242fea6 Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Thu, 1 Aug 2024 10:00:12 +0200 Subject: [PATCH] Allow using arrow keys in hotspot tooltip editable texts Stop propagation of key event to prevent composite from navigating to different area. REDMINE-20763 --- .../src/contentElements/hotspots/Tooltip.js | 68 ++++++++++++------- .../hotspots/Tooltip.module.css | 5 +- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.js b/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.js index 43542b354..dd4ba8a3e 100644 --- a/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.js +++ b/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.js @@ -32,6 +32,13 @@ import {getTooltipReferencePosition} from './getTooltipReferencePosition'; import styles from './Tooltip.module.css'; +const arrowKeys = [ + 'ArrowUp', + 'ArrowDown', + 'ArrowLeft', + 'ArrowRight' +]; + export function Tooltip({ area, contentElementId, portraitMode, configuration, visible, active, @@ -124,6 +131,13 @@ export function Tooltip({ }); } + function handleKeyDown(event) { + if (arrowKeys.includes(event.key) && isEditable) { + event.stopPropagation(); + event.preventDefault(); + } + } + function presentOrEditing(propertyName) { return !utils.isBlankEditableTextValue(tooltipTexts[area.id]?.[propertyName]) || (isEditable && active) || @@ -171,32 +185,34 @@ export function Tooltip({ } - {presentOrEditing('title') && -

- - handleTextChange('title', value)} - placeholder={t('pageflow_scrolled.inline_editing.type_heading')} /> - -

} - {presentOrEditing('description') && - handleTextChange('description', value)} - scaleCategory="hotspotsTooltipDescription" - placeholder={t('pageflow_scrolled.inline_editing.type_text')} />} - {presentOrEditing('link') && - - handleLinkChange(value)}> - handleTextChange('link', value)} - placeholder={t('pageflow_scrolled.inline_editing.type_text')} /> - › - - } +
+ {presentOrEditing('title') && +

+ + handleTextChange('title', value)} + placeholder={t('pageflow_scrolled.inline_editing.type_heading')} /> + +

} + {presentOrEditing('description') && + handleTextChange('description', value)} + scaleCategory="hotspotsTooltipDescription" + placeholder={t('pageflow_scrolled.inline_editing.type_text')} />} + {presentOrEditing('link') && + + handleLinkChange(value)}> + handleTextChange('link', value)} + placeholder={t('pageflow_scrolled.inline_editing.type_text')} /> + › + + } +
diff --git a/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.module.css b/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.module.css index 6bff9bc90..150baac64 100644 --- a/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.module.css +++ b/entry_types/scrolled/package/src/contentElements/hotspots/Tooltip.module.css @@ -102,12 +102,11 @@ margin: 0; } -.box > h3, -.box > div { +.box h3 { margin-bottom: 0.5rem; } -.box > :last-child { +.box h3:last-child { margin-bottom: 0; }