Skip to content

Commit af18f6d

Browse files
committed
fix: visually hidden is complete style based now - no css
1 parent 56ebcc9 commit af18f6d

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed
Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
11
'use client';
2-
import React from 'react';
2+
import React, { CSSProperties } from 'react';
33
import Primitive from '~/core/primitives/Primitive';
44
import { customClassSwitcher } from '~/core';
55
import { clsx } from 'clsx';
6+
67
const COMPONENT_NAME = 'VisuallyHidden';
78

89
export type VisuallyHiddenProps = {
910
children: React.ReactNode;
1011
customRootClass?: string;
1112
className?: string;
1213
asChild?: boolean;
13-
props: Record<string, any>[];
14-
}
14+
style?: CSSProperties;
15+
} & React.HTMLAttributes<HTMLDivElement>;
16+
17+
const VISUALLY_HIDDEN_STYLES: CSSProperties = {
18+
position: 'absolute',
19+
width: '1px',
20+
height: '1px',
21+
margin: '-1px',
22+
border: '0',
23+
padding: '0',
24+
whiteSpace: 'nowrap',
25+
clip: 'rect(0 0 0 0)',
26+
clipPath: 'inset(50%)',
27+
overflow: 'hidden',
28+
pointerEvents: 'none',
29+
userSelect: 'none',
30+
visibility: 'hidden'
31+
} as const;
1532

16-
const VisuallyHidden = ({ children, customRootClass, className, ...props }: VisuallyHiddenProps) => {
33+
const VisuallyHidden = ({
34+
children,
35+
customRootClass,
36+
className,
37+
style = {},
38+
...props
39+
}: VisuallyHiddenProps) => {
1740
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);
18-
return <Primitive.div className={clsx(rootClass, className)} {...props}>{children}</Primitive.div>;
41+
42+
return (
43+
<Primitive.div
44+
className={clsx(rootClass, className)}
45+
style={{ ...VISUALLY_HIDDEN_STYLES, ...style }} // overriding possible
46+
{...props}
47+
>
48+
{children}
49+
</Primitive.div>
50+
);
1951
};
52+
2053
VisuallyHidden.displayName = COMPONENT_NAME;
2154

2255
export default VisuallyHidden;

styles/themes/components/visuallyhidden.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

styles/themes/default.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
@use "components/scroll-area";
3232
@use "components/switch";
3333
@use "components/skeleton";
34-
@use "components/visuallyhidden";
3534
@use "components/collapsible";
3635
@use "components/tab-nav";
3736
@use "components/select";

0 commit comments

Comments
 (0)