Skip to content

Commit 171b352

Browse files
feat(dismissible-tag): make tooltip position configurable (#20155)
* feat(align): add dismisstooltipalign prop * feat(WC): dismisstooltipalign attribute * fix: snapshot * fix: rename dismissTooltipAlign to dismissTooltipAlignment --------- Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
1 parent d66cc6a commit 171b352

File tree

6 files changed

+109
-4
lines changed

6 files changed

+109
-4
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,6 +3075,25 @@ Map {
30753075
"disabled": {
30763076
"type": "bool",
30773077
},
3078+
"dismissTooltipAlignment": {
3079+
"args": [
3080+
[
3081+
"top",
3082+
"bottom",
3083+
"left",
3084+
"right",
3085+
"top-start",
3086+
"top-end",
3087+
"bottom-start",
3088+
"bottom-end",
3089+
"left-end",
3090+
"left-start",
3091+
"right-end",
3092+
"right-start",
3093+
],
3094+
],
3095+
"type": "oneOf",
3096+
},
30783097
"dismissTooltipLabel": {
30793098
"type": "string",
30803099
},

packages/react/src/components/Tag/DismissibleTag.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { isEllipsisActive } from './isEllipsisActive';
2828
import mergeRefs from '../../tools/mergeRefs';
2929
import { AILabel } from '../AILabel';
3030
import { isComponentElement } from '../../internal';
31+
import { PopoverAlignment } from '../Popover';
3132

3233
export interface DismissibleTagBaseProps {
3334
/**
@@ -45,6 +46,11 @@ export interface DismissibleTagBaseProps {
4546
*/
4647
disabled?: boolean;
4748

49+
/**
50+
* Specify the tooltip alignment for the dismiss button
51+
*/
52+
dismissTooltipAlignment?: PopoverAlignment;
53+
4854
/**
4955
* Provide a custom tooltip label for the dismiss button
5056
*/
@@ -118,6 +124,7 @@ const DismissibleTag = forwardRef(
118124
text,
119125
tagTitle,
120126
type,
127+
dismissTooltipAlignment = 'bottom',
121128
dismissTooltipLabel = 'Dismiss tag',
122129
...other
123130
}: DismissibleTagProps<T>,
@@ -187,7 +194,7 @@ const DismissibleTag = forwardRef(
187194
)}
188195
<Tooltip
189196
label={dismissActionLabel}
190-
align="bottom"
197+
align={dismissTooltipAlignment}
191198
className={tooltipClasses}
192199
leaveDelayMs={0}
193200
closeOnActivation>
@@ -221,6 +228,24 @@ DismissibleTag.propTypes = {
221228
*/
222229
disabled: PropTypes.bool,
223230

231+
/**
232+
* Specify the tooltip alignment for the dismiss button
233+
*/
234+
dismissTooltipAlignment: PropTypes.oneOf([
235+
'top',
236+
'bottom',
237+
'left',
238+
'right',
239+
'top-start',
240+
'top-end',
241+
'bottom-start',
242+
'bottom-end',
243+
'left-end',
244+
'left-start',
245+
'right-end',
246+
'right-start',
247+
]),
248+
224249
/**
225250
* Provide a custom tooltip label for the dismiss button
226251
*/

packages/react/src/components/Tag/InteractiveTag.stories.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -410,6 +410,7 @@ export const Dismissible = (args) => {
410410
text={tag.text}
411411
tagTitle={tag.tagTitle}
412412
title="Dismiss"
413+
dismissTooltipAlignment={args.dismissTooltipAlignment}
413414
onClose={(e) => {
414415
e.preventDefault();
415416
handleClose(tag);
@@ -425,6 +426,7 @@ export const Dismissible = (args) => {
425426
Dismissible.args = {
426427
disabled: false,
427428
size: 'md',
429+
dismissTooltipAlignment: 'bottom',
428430
};
429431

430432
Dismissible.argTypes = {
@@ -449,4 +451,25 @@ Dismissible.argTypes = {
449451
type: 'select',
450452
},
451453
},
454+
dismissTooltipAlignment: {
455+
options: [
456+
'top',
457+
'top-start',
458+
'top-end',
459+
'bottom',
460+
'bottom-start',
461+
'bottom-end',
462+
'left',
463+
'left-start',
464+
'left-end',
465+
'right',
466+
'right-start',
467+
'right-end',
468+
],
469+
control: { type: 'select' },
470+
description: 'Specify the tooltip alignment for the dismiss button',
471+
table: {
472+
defaultValue: { summary: 'bottom' },
473+
},
474+
},
452475
};

packages/web-components/src/components/tag/__tests__/__snapshots__/tag-test.snap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ snapshots['cds-tag should render'] = `<cds-tag
1212
/* end snapshot cds-tag should render */
1313

1414
snapshots['cds-tag cds-dismissible-tag should render'] = `<cds-dismissible-tag
15+
dismiss-tooltip-alignment="bottom"
1516
open=""
1617
size="md"
1718
tag-title="Close tag"

packages/web-components/src/components/tag/dismissible-tag.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
134134
@property({ type: Boolean, reflect: true })
135135
disabled = false;
136136

137+
/**
138+
* Specify the tooltip alignment for the dismiss button
139+
*/
140+
@property({
141+
type: String,
142+
attribute: 'dismiss-tooltip-alignment',
143+
reflect: true,
144+
})
145+
dismissTooltipAlignment = 'bottom';
146+
137147
/**
138148
* Provide a custom tooltip label for the dismiss button
139149
*/
@@ -180,6 +190,7 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
180190
tagTitle,
181191
text,
182192
dismissTooltipLabel,
193+
dismissTooltipAlignment,
183194
} = this;
184195

185196
const dismissLabel = `Dismiss "${text}"`;
@@ -199,7 +210,7 @@ class CDSDismissibleTag extends HostListenerMixin(FocusMixin(CDSTag)) {
199210
<slot name="decorator" @slotchange="${handleAILabelSlotChange}"></slot>
200211
<slot name="ai-label" @slotchange="${handleAILabelSlotChange}"></slot>
201212
<slot name="slug" @slotchange="${handleAILabelSlotChange}"></slot>
202-
<cds-tooltip align="bottom" enter-delay-ms=${0}>
213+
<cds-tooltip align=${dismissTooltipAlignment} enter-delay-ms=${0}>
203214
<button
204215
class="sb-tooltip-trigger"
205216
role="button"

packages/web-components/src/components/tag/tag.stories.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import '../popover';
1616
import '../ai-label';
1717
import '../button';
1818
import '../icon-button';
19+
import { POPOVER_ALIGNMENT } from '../popover/defs';
1920

2021
const content = html`
2122
<div slot="body-text">
@@ -69,6 +70,21 @@ const types = [
6970
'outline',
7071
];
7172

73+
const tooltipAlignments = {
74+
[`top`]: POPOVER_ALIGNMENT.TOP,
75+
[`top-left`]: POPOVER_ALIGNMENT.TOP_LEFT,
76+
[`top-right`]: POPOVER_ALIGNMENT.TOP_RIGHT,
77+
[`bottom`]: POPOVER_ALIGNMENT.BOTTOM,
78+
[`bottom-left`]: POPOVER_ALIGNMENT.BOTTOM_LEFT,
79+
[`bottom-right`]: POPOVER_ALIGNMENT.BOTTOM_RIGHT,
80+
[`left`]: POPOVER_ALIGNMENT.LEFT,
81+
[`left-bottom`]: POPOVER_ALIGNMENT.LEFT_BOTTOM,
82+
[`left-top`]: POPOVER_ALIGNMENT.LEFT_TOP,
83+
[`right`]: POPOVER_ALIGNMENT.RIGHT,
84+
[`right-bottom`]: POPOVER_ALIGNMENT.RIGHT_BOTTOM,
85+
[`right-top`]: POPOVER_ALIGNMENT.RIGHT_TOP,
86+
};
87+
7288
const defaultArgs = {
7389
disabled: false,
7490
size: TAG_SIZE.MEDIUM,
@@ -94,11 +110,20 @@ export const Dismissible = {
94110
control: 'text',
95111
description: 'Provide text to be rendered inside of a the tag.',
96112
},
113+
dismissTooltipAlignment: {
114+
control: 'select',
115+
options: tooltipAlignments,
116+
description: 'Specify the tooltip alignment for the dismiss button',
117+
table: {
118+
defaultValue: { summary: 'bottom' },
119+
},
120+
},
97121
},
98122
args: {
99123
...defaultArgs,
124+
dismissTooltipAlignment: 'bottom',
100125
},
101-
render: ({ disabled, size, text }) => {
126+
render: ({ disabled, size, text, dismissTooltipAlignment }) => {
102127
const tags = [
103128
{
104129
type: 'red',
@@ -168,6 +193,7 @@ export const Dismissible = {
168193
tag-title="${tag.tagTitle}"
169194
type="${tag.type}"
170195
size="${size}"
196+
dismiss-tooltip-alignment="${dismissTooltipAlignment}"
171197
>${Asleep16({ slot: 'icon' })}</cds-dismissible-tag
172198
>`
173199
)}`;

0 commit comments

Comments
 (0)