Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FaCircleExclamationIcon } from '../Icon'
import { Cluster, Stack } from '../Layout'
import { StatusLabel } from '../StatusLabel'
import { Text, type TextProps } from '../Text'
import { VisuallyHiddenText, visuallyHiddenTextClassNameGenerator } from '../VisuallyHiddenText'
import { VisuallyHiddenText, visuallyHiddenTextClassName } from '../VisuallyHiddenText'

import type { Gap } from '../../types'

Expand Down Expand Up @@ -229,7 +229,7 @@ export const ActualFormControl: FC<Props & ElementProps> = ({
return {
wrapper: generators.wrapper({ className }),
label: generators.label({
className: label.dangerouslyHide ? visuallyHiddenTextClassNameGenerator() : '',
className: label.dangerouslyHide ? visuallyHiddenTextClassName : '',
}),
errorList: generators.errorList(),
errorIcon: generators.errorIcon(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import innerText from 'react-innertext'
import { tv } from 'tailwind-variants'

import { STYLE_TYPE_MAP, Text, type TextProps } from '../../Text'
import { VisuallyHiddenText, visuallyHiddenTextClassNameGenerator } from '../../VisuallyHiddenText'
import { VisuallyHiddenText, visuallyHiddenTextClassName } from '../../VisuallyHiddenText'

import type { ElementProps } from '../Heading'

Expand Down Expand Up @@ -38,8 +38,6 @@ const classNameGenerator = tv({
},
})

const PSEUDO_TITLE_CLASS_NAME = visuallyHiddenTextClassNameGenerator()

export const PageHeading = memo<Props & ElementProps>(
({
size,
Expand Down Expand Up @@ -79,7 +77,7 @@ export const PageHeading = memo<Props & ElementProps>(
document.createElement('div')) as HTMLDivElement

pseudoTitle.setAttribute('id', pseudoTitleId)
pseudoTitle.setAttribute('class', PSEUDO_TITLE_CLASS_NAME)
pseudoTitle.setAttribute('class', visuallyHiddenTextClassName)
pseudoTitle.setAttribute('aria-live', 'polite')
document.body.prepend(pseudoTitle)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { type ComponentProps, type ElementType, type PropsWithChildren, memo, useMemo } from 'react'
import { tv } from 'tailwind-variants'

export const visuallyHiddenTextClassNameGenerator = tv({
const visuallyHiddenTextClassNameGenerator = tv({
base: 'shr-absolute shr-h-px shr-w-px shr-overflow-hidden shr-whitespace-nowrap shr-border-0 shr-p-0 [clip-path:inset(100%)] [clip:rect(0_0_0_0)]',
})

export const visuallyHiddenTextClassName = visuallyHiddenTextClassNameGenerator()

type Props<T extends ElementType> = PropsWithChildren<{
as?: T
}> &
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { VisuallyHiddenText, visuallyHiddenTextClassNameGenerator } from './VisuallyHiddenText'
export { VisuallyHiddenText, visuallyHiddenTextClassName } from './VisuallyHiddenText'
Loading