-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove CSS modules feature flag from VisuallyHidden
- Loading branch information
Showing
3 changed files
with
6 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,17 @@ | ||
import styled from 'styled-components' | ||
import type {SxProp} from '../sx' | ||
import sx from '../sx' | ||
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent' | ||
import {clsx} from 'clsx' | ||
import {useFeatureFlag} from '../FeatureFlags' | ||
import React, {type HTMLAttributes} from 'react' | ||
import classes from './VisuallyHidden.module.css' | ||
|
||
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga' | ||
|
||
/** | ||
* Provides a component that implements the "visually hidden" technique. This is | ||
* analagous to the common `sr-only` class. Children that are rendered inside | ||
* this component will not be visible but will be available to screen readers. | ||
* | ||
* Note: if this component, or a descendant, has focus then this component will | ||
* no longer be visually hidden. | ||
* | ||
* @see https://www.scottohara.me/blog/2023/03/21/visually-hidden-hack.html | ||
*/ | ||
const StyledVisuallyHidden = toggleStyledComponent( | ||
CSS_MODULES_FEATURE_FLAG, | ||
'span', | ||
styled.span<SxProp>` | ||
&:not(:focus):not(:active):not(:focus-within) { | ||
clip-path: inset(50%); | ||
height: 1px; | ||
overflow: hidden; | ||
position: absolute; | ||
white-space: nowrap; | ||
width: 1px; | ||
} | ||
${sx} | ||
`, | ||
) | ||
|
||
export const VisuallyHidden = ({className, children, ...rest}: VisuallyHiddenProps) => { | ||
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG) | ||
return ( | ||
<StyledVisuallyHidden className={clsx(className, enabled && classes.VisuallyHidden)} {...rest}> | ||
<span className={clsx(className, classes.VisuallyHidden)} {...rest}> | ||
{children} | ||
</StyledVisuallyHidden> | ||
</span> | ||
) | ||
} | ||
|
||
export type VisuallyHiddenProps = React.PropsWithChildren< | ||
HTMLAttributes<HTMLSpanElement> & { | ||
className?: string | ||
} & SxProp | ||
} | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters