Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Popover text inline trigger #3224

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/popover/text-wrap.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const triggerPermutations = createPermutations<PopoverProps & { size: PopoverPro
'Reallylongpopovercontentwithalotoftextbutnospacesthatwillprobablyoverflowthepopovertrigger',
],
wrapTriggerText: [true, false],
triggerType: ['text', 'text-inline'],
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12178,13 +12178,15 @@ that don't have visible text, and to distinguish between multiple triggers with
{
"defaultValue": "'text'",
"description": "Specifies the type of content inside the trigger region. The following types are available:
- \`text\` - Use for inline text triggers.
- \`text\` - Use for triggers containing inline components, like status indicator.
- \`text-inline\` - Use for triggers containing plain text only.
- \`custom\` - Use for the [button](/components/button/) component.",
"inlineType": {
"name": "PopoverProps.TriggerType",
"type": "union",
"values": [
"text",
"text-inline",
"custom",
],
},
Expand Down
5 changes: 3 additions & 2 deletions src/popover/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface PopoverProps extends BaseComponentProps {

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

export interface Ref {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/popover/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function InternalPopover(
const [visible, setVisible] = useState(false);

const focusTrigger = useCallback(() => {
if (triggerType === 'text') {
if (['text', 'text-inline'].includes(triggerType)) {
triggerRef.current?.focus();
} else {
triggerRef.current && getFirstFocusable(triggerRef.current)?.focus();
Expand Down Expand Up @@ -198,7 +198,7 @@ function InternalPopover(
});
}}
>
{triggerType === 'text' ? (
{['text', 'text-inline'].includes(triggerType) ? (
<button
{...triggerProps}
className={clsx(triggerProps.className, wrapTriggerText === false && styles['overflow-ellipsis'])}
Expand Down
26 changes: 25 additions & 1 deletion src/popover/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@import './container';
@import './motion';

$trigger-underline-offset: 0.25em;

.root {
@include styles.styles-reset;
color: inherit;
Expand All @@ -36,8 +38,31 @@
@include styles.text-wrapping;
}

.trigger-type-text-inline {
border-block: 0;
/*
This transparent border is necessary to maintain space between the trigger and the bottom-positioned popover.
*/
border-block-end: awsui.$border-divider-list-width dashed transparent;
text-decoration: underline dashed currentColor;
text-decoration-thickness: awsui.$border-divider-list-width;
text-underline-offset: $trigger-underline-offset;

&.overflow-ellipsis {
/*
This style needs because of the overflow: hidden would otherwise conceal the underline styles.
*/
padding-block-end: calc(#{$trigger-underline-offset} + #{awsui.$border-divider-list-width});
}
}

.trigger-type-text {
border-block: 0;
border-block-end: awsui.$border-divider-list-width dashed currentColor;
}

.trigger-type-text-inline,
.trigger-type-text {
border-inline: 0;
margin-block: 0;
margin-inline: 0;
Expand All @@ -46,7 +71,6 @@
background-color: transparent;

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

&:focus {
outline: none;
Expand Down
Loading