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

Add tooltip to the statusTag of the PageHeader #939

Merged
merged 2 commits into from
Dec 13, 2024
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
8 changes: 6 additions & 2 deletions lib/experimental/Information/Tags/BaseTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { forwardRef, ReactNode } from "react"
type Props = {
left?: ReactNode
text: string
/**
* Sometimes you need to clarify the status for screen reader users
* E.g., when showing a tooltip for sighted user, provide the tootip text to this prop because tooltips aren't accessible
*/
additionalAccesibleText?: string
onClick?: () => void
className?: string
Expand All @@ -21,10 +25,10 @@ export const BaseTag = forwardRef<HTMLDivElement, Props>(
onClick={onClick}
>
{left}
<span>{text}</span>
{additionalAccesibleText && (
<span className="sr-only">{additionalAccesibleText}</span>
<span className="sr-only">, {additionalAccesibleText}</span>
)}
<span>{text}</span>
</div>
)
)
Expand Down
9 changes: 7 additions & 2 deletions lib/experimental/Information/Tags/StatusTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export type StatusVariant = Variant
interface Props {
text: string
variant: Variant
/**
* Sometimes you need to clarify the status for screen reader users
* E.g., when showing a tooltip for sighted user, provide the tootip text to this prop because tooltips aren't accessible
*/
additionalAccesibleText?: string
}

export const StatusTag = forwardRef<HTMLDivElement, Props>(
({ text, variant }, ref) => {
({ text, additionalAccesibleText, variant }, ref) => {
useTextFormatEnforcer(text, { disallowEmpty: true })

return (
Expand Down Expand Up @@ -44,7 +49,7 @@ export const StatusTag = forwardRef<HTMLDivElement, Props>(
aria-hidden
/>
}
additionalAccesibleText="Status"
additionalAccesibleText={additionalAccesibleText}
text={text}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const FirstLevelWithTag: Story = {
statusTag: {
text: "Published",
variant: "positive",
tooltip: "Tooltip description",
},
},
}
Expand Down
16 changes: 15 additions & 1 deletion lib/experimental/Navigation/Header/PageHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Icon, IconType } from "@/components/Utilities/Icon"
import type { StatusVariant } from "@/experimental/Information/Tags/StatusTag"
import { StatusTag } from "@/experimental/Information/Tags/StatusTag"
import { useSidebar } from "@/experimental/Navigation/ApplicationFrame/FrameProvider"
import { Tooltip } from "@/experimental/Overlays/Tooltip"
import { Menu } from "@/icons/app"
import { cn } from "@/lib/utils"
import { AnimatePresence, motion } from "framer-motion"
Expand Down Expand Up @@ -35,6 +36,7 @@ type HeaderProps = {
statusTag?: {
text: string
variant: StatusVariant
tooltip?: string
}
breadcrumbs?: BreadcrumbItemType[]
actions?: PageAction[]
Expand Down Expand Up @@ -99,7 +101,19 @@ export function PageHeader({
<div className="flex items-center">
{!hasNavigation && hasStatus && (
<div className="pe-3">
<StatusTag text={statusTag.text} variant={statusTag.variant} />
{statusTag.tooltip ? (
<Tooltip label={statusTag.tooltip}>
<div>
<StatusTag
text={statusTag.text}
variant={statusTag.variant}
additionalAccesibleText={statusTag.tooltip}
/>
</div>
</Tooltip>
) : (
<StatusTag text={statusTag.text} variant={statusTag.variant} />
)}
</div>
)}
{hasStatus && hasActions && (
Expand Down
Loading