Skip to content

Commit 64081ef

Browse files
nmergetmfranzke
andauthored
refactor: replace title-attribute for removable tag with DBTooltip (#4218)
* refactor: replace title for remove tag with tooltip * fix: issue with wrong import * chore: update snapshot * fix: issue with aria-describedby for tooltip * chore: update snapshots --------- Co-authored-by: Maximilian Franzke <787658+mfranzke@users.noreply.github.com>
1 parent dcd4eaa commit 64081ef

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed

__snapshots__/tag/showcase/chromium-highContrast/should-have-same-aria-snapshot/DBTag-should-have-same-aria-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- link "Behavior arrow_up_right\" / \""
1010
- group "Behavior":
1111
- text: (Default) Static Removable
12-
- button "cross\" / \" Remove"
12+
- button "Remove": cross" / "
1313
- button "Interactive (Button)"
1414
- link "Interactive (Link)"
1515
- checkbox "Interactive (Checkbox) circle\" / \""

__snapshots__/tag/showcase/chromium/should-have-same-aria-snapshot/DBTag-should-have-same-aria-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- link "Behavior arrow_up_right\" / \""
1010
- group "Behavior":
1111
- text: (Default) Static Removable
12-
- button "cross\" / \" Remove"
12+
- button "Remove": cross" / "
1313
- button "Interactive (Button)"
1414
- link "Interactive (Link)"
1515
- checkbox "Interactive (Checkbox) circle\" / \""

__snapshots__/tag/showcase/mobile-chrome/should-have-same-aria-snapshot/DBTag-should-have-same-aria-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- link "Behavior arrow_up_right\" / \""
1010
- group "Behavior":
1111
- text: (Default) Static Removable
12-
- button "cross\" / \" Remove"
12+
- button "Remove": cross" / "
1313
- button "Interactive (Button)"
1414
- link "Interactive (Link)"
1515
- checkbox "Interactive (Checkbox) circle\" / \""

__snapshots__/tag/showcase/mobile-safari/should-have-same-aria-snapshot/DBTag-should-have-same-aria-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- link "Behavior arrow_up_right\" / \""
1010
- group "Behavior":
1111
- text: (Default) Static Removable
12-
- button "cross\" / \" Remove"
12+
- button "Remove": cross" / "
1313
- button "Interactive (Button)"
1414
- link "Interactive (Link)"
1515
- checkbox "Interactive (Checkbox) circle\" / \""

__snapshots__/tag/showcase/webkit/should-have-same-aria-snapshot/DBTag-should-have-same-aria-snapshot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- link "Behavior arrow_up_right\" / \""
1010
- group "Behavior":
1111
- text: (Default) Static Removable
12-
- button "cross\" / \" Remove"
12+
- button "Remove": cross" / "
1313
- button "Interactive (Button)"
1414
- link "Interactive (Link)"
1515
- checkbox "Interactive (Checkbox) circle\" / \""
Loading

packages/components/src/components/tag/tag.lite.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DBTagProps, DBTagState } from './model';
1212
import { cls, getBooleanAsString, getHideProp } from '../../utils';
1313
import { DEFAULT_REMOVE } from '../../shared/constants';
1414
import { ClickEvent } from '../../shared/model';
15+
import DBTooltip from '../tooltip/tooltip.lite';
1516

1617
useMetadata({});
1718
useDefaultProps<DBTagProps>({});
@@ -84,9 +85,10 @@ export default function DBTag(props: DBTagProps) {
8485
data-size="small"
8586
data-no-text="true"
8687
data-variant="ghost"
87-
type="button"
88-
title={state.getRemoveButtonText()}>
89-
{state.getRemoveButtonText()}
88+
type="button">
89+
<DBTooltip variant="label">
90+
{state.getRemoveButtonText()}
91+
</DBTooltip>
9092
</button>
9193
</Show>
9294
</div>

packages/components/src/components/tooltip/model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ import {
99
PopoverState
1010
} from '../../shared/model';
1111

12+
export const TooltipVariantList = ['description', 'label'] as const;
13+
export type TooltipVariantType = (typeof TooltipVariantList)[number];
14+
1215
export type DBTooltipDefaultProps = {
16+
/**
17+
* Show/Hides arrow
18+
*/
1319
showArrow?: boolean | string;
20+
/**
21+
* Change the behavior of the tooltip:
22+
* - description: Adds `aria-describedby` to parent
23+
* - label: Adds `aria-labelledby` to parent
24+
*/
25+
variant?: TooltipVariantType;
1426
};
1527

1628
export type DBTooltipProps = DBTooltipDefaultProps &

packages/components/src/components/tooltip/tooltip.lite.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ export default function DBTooltip(props: DBTooltipProps) {
4949
);
5050
});
5151
parent.setAttribute('data-has-tooltip', 'true');
52-
parent.setAttribute('aria-describedby', state._id);
52+
53+
if (props.variant === 'label') {
54+
parent.setAttribute('aria-labelledby', state._id);
55+
} else {
56+
parent.setAttribute('aria-describedby', state._id);
57+
}
5358
}
5459

5560
state.initialized = false;

0 commit comments

Comments
 (0)