File tree Expand file tree Collapse file tree
packages/react-textarea/src/components/copilot-textarea/base-copilot-textarea Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525 BaseAutosuggestionsConfig ,
2626 defaultBaseAutosuggestionsConfig ,
2727} from "../../../types/autosuggestions-config" ;
28+ import { defaultStylesConsideringClassname } from "./default-styles-considering-classname" ;
2829import { renderElement } from "./render-element" ;
2930import { makeRenderPlaceholderFunction } from "./render-placeholder" ;
3031
@@ -132,9 +133,10 @@ export function BaseCopilotTextarea(
132133 ...propsToForward
133134 } = props ;
134135
136+ const { className } = propsToForward ;
135137 const moddedStyle = {
136- overflow : "auto" ,
137- ...style , // to merge in styles passed via props if any
138+ ... defaultStylesConsideringClassname ( className ) ,
139+ ...style ,
138140 } ;
139141
140142 return (
Original file line number Diff line number Diff line change 1+ // A slightly hacky way to get the default styles of a CopilotTextarea considering its className --
2+ // to allow for outside (tailwindCSS) overrides of the default styles.
3+ export function defaultStylesConsideringClassname (
4+ className : string | undefined
5+ ) {
6+ let defaultStyles : React . CSSProperties = { } ;
7+ const classNameChunks = ( className ?? "" ) . split ( " " ) ?? [ ] ;
8+
9+ // white background color
10+ if ( ! classNameChunks . some ( ( chunk ) => chunk . startsWith ( "bg-" ) ) ) {
11+ defaultStyles = {
12+ ...defaultStyles ,
13+ backgroundColor : "white" ,
14+ } ;
15+ }
16+
17+ // overflow-y: auto
18+ // if there is a overflow- which is NOT overflow-x, then we don't add overflow-y: auto
19+ if (
20+ ! classNameChunks . some (
21+ ( chunk ) =>
22+ chunk . startsWith ( "overflow-" ) && ! chunk . startsWith ( "overflow-x" )
23+ )
24+ ) {
25+ defaultStyles = {
26+ ...defaultStyles ,
27+ overflowY : "auto" ,
28+ } ;
29+ }
30+
31+ // resize-y
32+ // if there is a resize- which is NOT resize-x, then we don't add resize-y
33+ if (
34+ ! classNameChunks . some (
35+ ( chunk ) => chunk . startsWith ( "resize-" ) && ! chunk . startsWith ( "resize-x" )
36+ )
37+ ) {
38+ defaultStyles = {
39+ ...defaultStyles ,
40+ resize : "vertical" ,
41+ } ;
42+ }
43+
44+ return defaultStyles ;
45+ }
You can’t perform that action at this time.
0 commit comments