Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/dirty-fans-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Update `Textarea` component to use CSS module
34 changes: 34 additions & 0 deletions packages/react/src/Textarea/TextArea.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.TextArea {
width: 100%;
font-family: inherit;
font-size: inherit;
color: inherit;
resize: both;
background-color: transparent;
border: 0;
appearance: none;
}

.TextArea:focus {
outline: 0;
}

.TextArea[resize='none'] {
resize: none;
}

.TextArea[resize='both'] {
resize: both;
}

.TextArea[resize='horizontal'] {
resize: horizontal;
}

.TextArea[resize='vertical'] {
resize: vertical;
}

.TextArea:disabled {
resize: none;
}
59 changes: 36 additions & 23 deletions packages/react/src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {TextInputBaseWrapper} from '../internal/components/TextInputWrapper'
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
import type {SxProp} from '../sx'
import sx from '../sx'
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
import {clsx} from 'clsx'
import {useFeatureFlag} from '../FeatureFlags'
import classes from './TextArea.module.css'

export const DEFAULT_TEXTAREA_ROWS = 7
export const DEFAULT_TEXTAREA_COLS = 30
Expand Down Expand Up @@ -38,33 +42,39 @@ export type TextareaProps = {
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
SxProp

const StyledTextarea = styled.textarea<TextareaProps>`
border: 0;
font-size: inherit;
font-family: inherit;
background-color: transparent;
-webkit-appearance: none;
color: inherit;
width: 100%;
resize: both;
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_team'

&:focus {
outline: 0;
}
const StyledTextarea = toggleStyledComponent(
CSS_MODULES_FEATURE_FLAG,
'textarea',
styled.textarea<TextareaProps>`
border: 0;
font-size: inherit;
font-family: inherit;
background-color: transparent;
-webkit-appearance: none;
color: inherit;
width: 100%;
resize: both;

${props =>
props.resize &&
css`
resize: ${props.resize};
`}
&:focus {
outline: 0;
}

${props =>
props.disabled &&
css`
resize: none;
`}
${props =>
props.resize &&
css`
resize: ${props.resize};
`}

${props =>
props.disabled &&
css`
resize: none;
`}
${sx};
`
`,
)

/**
* An accessible, native textarea component that supports validation states.
Expand All @@ -88,6 +98,8 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
}: TextareaProps,
ref,
): ReactElement => {
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)

return (
<TextInputBaseWrapper
sx={sxProp}
Expand All @@ -106,6 +118,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
disabled={disabled}
rows={rows}
cols={cols}
className={clsx(enabled && classes.TextArea, className)}
{...rest}
/>
</TextInputBaseWrapper>
Expand Down
Loading