Skip to content

Commit a013605

Browse files
fix: ShadCN styles scoping & ref error (#896)
* Fixed ShadCN styles scoping & ref error * Added comment
1 parent f3a5869 commit a013605

File tree

4 files changed

+477
-50
lines changed

4 files changed

+477
-50
lines changed

packages/shadcn/src/form/TextInput.tsx

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,60 @@ import { forwardRef } from "react";
44

55
import { useShadCNComponentsContext } from "../ShadCNComponentsContext";
66

7-
export const TextInput = forwardRef(
8-
(props: ComponentProps["Generic"]["Form"]["TextInput"]) => {
9-
const {
10-
className,
11-
name,
12-
label,
13-
icon, // TODO: implement
14-
value,
15-
autoFocus,
16-
placeholder,
17-
onKeyDown,
18-
onChange,
19-
onSubmit,
20-
...rest
21-
} = props;
7+
export const TextInput = forwardRef<
8+
HTMLInputElement,
9+
ComponentProps["Generic"]["Form"]["TextInput"]
10+
>((props, ref) => {
11+
const {
12+
className,
13+
name,
14+
label,
15+
icon, // TODO: implement
16+
value,
17+
autoFocus,
18+
placeholder,
19+
onKeyDown,
20+
onChange,
21+
onSubmit,
22+
...rest
23+
} = props;
2224

23-
assertEmpty(rest);
25+
assertEmpty(rest);
2426

25-
const ShadCNComponents = useShadCNComponentsContext()!;
26-
27-
if (!label) {
28-
return (
29-
<ShadCNComponents.Input.Input
30-
aria-label={name}
31-
name={name}
32-
autoFocus={autoFocus}
33-
placeholder={placeholder}
34-
value={value}
35-
onKeyDown={onKeyDown}
36-
onChange={onChange}
37-
onSubmit={onSubmit}
38-
/>
39-
);
40-
}
27+
const ShadCNComponents = useShadCNComponentsContext()!;
4128

29+
if (!label) {
4230
return (
43-
<div>
44-
<ShadCNComponents.Label.Label htmlFor={label}>
45-
{label}
46-
</ShadCNComponents.Label.Label>
47-
<ShadCNComponents.Input.Input
48-
className={className}
49-
id={label}
50-
name={name}
51-
autoFocus={autoFocus}
52-
placeholder={placeholder}
53-
value={value}
54-
onKeyDown={onKeyDown}
55-
onChange={onChange}
56-
onSubmit={onSubmit}
57-
/>
58-
</div>
31+
<ShadCNComponents.Input.Input
32+
aria-label={name}
33+
name={name}
34+
autoFocus={autoFocus}
35+
placeholder={placeholder}
36+
value={value}
37+
onKeyDown={onKeyDown}
38+
onChange={onChange}
39+
onSubmit={onSubmit}
40+
ref={ref}
41+
/>
5942
);
6043
}
61-
);
44+
45+
return (
46+
<div>
47+
<ShadCNComponents.Label.Label htmlFor={label}>
48+
{label}
49+
</ShadCNComponents.Label.Label>
50+
<ShadCNComponents.Input.Input
51+
className={className}
52+
id={label}
53+
name={name}
54+
autoFocus={autoFocus}
55+
placeholder={placeholder}
56+
value={value}
57+
onKeyDown={onKeyDown}
58+
onChange={onChange}
59+
onSubmit={onSubmit}
60+
/>
61+
</div>
62+
);
63+
});

packages/shadcn/src/style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
@import "./tailwindStyles.css";
12
@import url("@blocknote/react/style.css");
23

3-
@tailwind base;
44
@tailwind components;
55
@tailwind utilities;
66

@@ -69,6 +69,7 @@
6969
.bn-shadcn * {
7070
@apply bn-border-border;
7171
}
72+
7273
.bn-shadcn .bn-editor {
7374
@apply bn-bg-background bn-text-foreground;
7475
}

0 commit comments

Comments
 (0)