Skip to content

Commit

Permalink
Merge pull request #2137 from tf/hotspot-keyboard-editing
Browse files Browse the repository at this point in the history
Improve hotspot tooltip keyboard editing
  • Loading branch information
tf authored Aug 1, 2024
2 parents a4cae0e + b4d1908 commit d3c05d7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -171,32 +185,34 @@ export function Tooltip({
<InlineFileRights context="afterElement" items={[{file: tooltipImageFile, label: 'image'}]} />
</div>
</>}
{presentOrEditing('title') &&
<h3 id={`hotspots-tooltip-title-${contentElementId}-${area.id}`}>
<Text inline scaleCategory="hotspotsTooltipTitle">
<EditableInlineText value={tooltipTexts[area.id]?.title}
onChange={value => handleTextChange('title', value)}
placeholder={t('pageflow_scrolled.inline_editing.type_heading')} />
</Text>
</h3>}
{presentOrEditing('description') &&
<EditableText value={tooltipTexts[area.id]?.description}
onChange={value => handleTextChange('description', value)}
scaleCategory="hotspotsTooltipDescription"
placeholder={t('pageflow_scrolled.inline_editing.type_text')} />}
{presentOrEditing('link') &&
<Text inline scaleCategory="hotspotsTooltipLink">
<EditableLink href={tooltipLinks[area.id]?.href}
openInNewTab={tooltipLinks[area.id]?.openInNewTab}
linkPreviewDisabled={utils.isBlankEditableTextValue(tooltipTexts[area.id]?.link)}
className={styles.link}
onChange={value => handleLinkChange(value)}>
<EditableInlineText value={tooltipTexts[area.id]?.link}
onChange={value => handleTextChange('link', value)}
placeholder={t('pageflow_scrolled.inline_editing.type_text')} />
</EditableLink>
</Text>}
<div onKeyDown={handleKeyDown}>
{presentOrEditing('title') &&
<h3 id={`hotspots-tooltip-title-${contentElementId}-${area.id}`}>
<Text inline scaleCategory="hotspotsTooltipTitle">
<EditableInlineText value={tooltipTexts[area.id]?.title}
onChange={value => handleTextChange('title', value)}
placeholder={t('pageflow_scrolled.inline_editing.type_heading')} />
</Text>
</h3>}
{presentOrEditing('description') &&
<EditableText value={tooltipTexts[area.id]?.description}
onChange={value => handleTextChange('description', value)}
scaleCategory="hotspotsTooltipDescription"
placeholder={t('pageflow_scrolled.inline_editing.type_text')} />}
{presentOrEditing('link') &&
<Text inline scaleCategory="hotspotsTooltipLink">
<EditableLink href={tooltipLinks[area.id]?.href}
openInNewTab={tooltipLinks[area.id]?.openInNewTab}
linkPreviewDisabled={utils.isBlankEditableTextValue(tooltipTexts[area.id]?.link)}
className={styles.link}
onChange={value => handleLinkChange(value)}>
<EditableInlineText value={tooltipTexts[area.id]?.link}
onChange={value => handleTextChange('link', value)}
placeholder={t('pageflow_scrolled.inline_editing.type_text')} />
</EditableLink>
</Text>}
</div>
</div>
</div>
</FloatingFocusManager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ export function EditableLink({

return (
<div className={styles.wrapper}>
{isSelected &&
<ActionButton text={href ?
t('pageflow_scrolled.inline_editing.change_link_destination') :
t('pageflow_scrolled.inline_editing.select_link_destination')}
icon="link"
position={actionButtonPosition}
onClick={handleButtonClick} />}
<LinkTooltipProvider disabled={linkPreviewDisabled}
position={linkPreviewPosition}
align="left"
Expand All @@ -39,6 +32,13 @@ export function EditableLink({
{children}
</LinkPreview>
</LinkTooltipProvider>
{isSelected &&
<ActionButton text={href ?
t('pageflow_scrolled.inline_editing.change_link_destination') :
t('pageflow_scrolled.inline_editing.select_link_destination')}
icon="link"
position={actionButtonPosition}
onClick={handleButtonClick} />}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function HoveringToolbar({position}) {
const rect = domRange.getBoundingClientRect()
const outerRect = outerRef.current.getBoundingClientRect()

el.style.opacity = 1;
el.style.visibility = 'visible';
el.style.left = `${rect.left - outerRect.left}px`;

if (position === 'above') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
z-index: 2;
top: -10000px;
left: -10000px;
opacity: 0;
visibility: hidden;
white-space: nowrap;
}

Expand Down

0 comments on commit d3c05d7

Please sign in to comment.