Skip to content

Commit e1c488b

Browse files
authored
chore: Underline styles for popover text trigger (#3060)
1 parent 76a85a0 commit e1c488b

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

Diff for: pages/popover/text-wrap.page.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const triggerPermutations = createPermutations<PopoverProps & { size: PopoverPro
2626
'Reallylongpopovercontentwithalotoftextbutnospacesthatwillprobablyoverflowthepopovertrigger',
2727
],
2828
wrapTriggerText: [true, false],
29+
triggerType: ['text', 'text-inline'],
2930
},
3031
]);
3132

Diff for: src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -12178,13 +12178,15 @@ that don't have visible text, and to distinguish between multiple triggers with
1217812178
{
1217912179
"defaultValue": "'text'",
1218012180
"description": "Specifies the type of content inside the trigger region. The following types are available:
12181-
- \`text\` - Use for inline text triggers.
12181+
- \`text\` - Use for triggers containing inline components, like status indicator.
12182+
- \`text-inline\` - Use for triggers containing plain text only.
1218212183
- \`custom\` - Use for the [button](/components/button/) component.",
1218312184
"inlineType": {
1218412185
"name": "PopoverProps.TriggerType",
1218512186
"type": "union",
1218612187
"values": [
1218712188
"text",
12189+
"text-inline",
1218812190
"custom",
1218912191
],
1219012192
},

Diff for: src/popover/interfaces.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export interface PopoverProps extends BaseComponentProps {
2323

2424
/**
2525
* Specifies the type of content inside the trigger region. The following types are available:
26-
* - `text` - Use for inline text triggers.
26+
* - `text` - Use for triggers containing inline components, like status indicator.
27+
* - `text-inline` - Use for triggers containing plain text only.
2728
* - `custom` - Use for the [button](/components/button/) component.
2829
*/
2930
triggerType?: PopoverProps.TriggerType;
@@ -114,7 +115,7 @@ export type Rect = BoundingBox & {
114115
export namespace PopoverProps {
115116
export type Position = 'top' | 'right' | 'bottom' | 'left';
116117
export type Size = 'small' | 'medium' | 'large';
117-
export type TriggerType = 'text' | 'custom';
118+
export type TriggerType = 'text' | 'text-inline' | 'custom';
118119

119120
export interface Ref {
120121
/**

Diff for: src/popover/internal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function InternalPopover(
7474
const [visible, setVisible] = useState(false);
7575

7676
const focusTrigger = useCallback(() => {
77-
if (triggerType === 'text') {
77+
if (['text', 'text-inline'].includes(triggerType)) {
7878
triggerRef.current?.focus();
7979
} else {
8080
triggerRef.current && getFirstFocusable(triggerRef.current)?.focus();
@@ -198,7 +198,7 @@ function InternalPopover(
198198
});
199199
}}
200200
>
201-
{triggerType === 'text' ? (
201+
{['text', 'text-inline'].includes(triggerType) ? (
202202
<button
203203
{...triggerProps}
204204
className={clsx(triggerProps.className, wrapTriggerText === false && styles['overflow-ellipsis'])}

Diff for: src/popover/styles.scss

+25-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
@import './container';
1313
@import './motion';
1414

15+
$trigger-underline-offset: 0.25em;
16+
1517
.root {
1618
@include styles.styles-reset;
1719
color: inherit;
@@ -36,8 +38,31 @@
3638
@include styles.text-wrapping;
3739
}
3840

41+
.trigger-type-text-inline {
42+
border-block: 0;
43+
/*
44+
This transparent border is necessary to maintain space between the trigger and the bottom-positioned popover.
45+
*/
46+
border-block-end: awsui.$border-divider-list-width dashed transparent;
47+
text-decoration: underline dashed currentColor;
48+
text-decoration-thickness: awsui.$border-divider-list-width;
49+
text-underline-offset: $trigger-underline-offset;
50+
51+
&.overflow-ellipsis {
52+
/*
53+
This line-height needs to be overridden because the overflow: hidden would otherwise conceal the underline styles.
54+
*/
55+
line-height: calc(1 + #{$trigger-underline-offset} + #{awsui.$border-divider-list-width});
56+
}
57+
}
58+
3959
.trigger-type-text {
4060
border-block: 0;
61+
border-block-end: awsui.$border-divider-list-width dashed currentColor;
62+
}
63+
64+
.trigger-type-text-inline,
65+
.trigger-type-text {
4166
border-inline: 0;
4267
margin-block: 0;
4368
margin-inline: 0;
@@ -46,7 +71,6 @@
4671
background-color: transparent;
4772

4873
cursor: pointer;
49-
border-block-end: awsui.$border-divider-list-width dashed currentColor;
5074

5175
&:focus {
5276
outline: none;

0 commit comments

Comments
 (0)