Skip to content

Commit 5c1187f

Browse files
committed
Allow hiding error message on Textarea
1 parent 226d4d9 commit 5c1187f

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/components/Textarea.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,27 @@ import React, {
1111
import { styled, css } from '@storybook/theming';
1212
import { color, typography } from './shared/styles';
1313

14+
const hidden = () => css`
15+
border: 0px !important;
16+
clip: rect(0 0 0 0) !important;
17+
-webkit-clip-path: inset(100%) !important;
18+
clip-path: inset(100%) !important;
19+
height: 1px !important;
20+
overflow: hidden !important;
21+
padding: 0px !important;
22+
position: absolute !important;
23+
white-space: nowrap !important;
24+
width: 1px !important;
25+
`;
26+
1427
const Label = styled.label<{ hideLabel: boolean }>`
15-
${(props) =>
16-
props.hideLabel &&
17-
css`
18-
border: 0px !important;
19-
clip: rect(0 0 0 0) !important;
20-
-webkit-clip-path: inset(100%) !important;
21-
clip-path: inset(100%) !important;
22-
height: 1px !important;
23-
overflow: hidden !important;
24-
padding: 0px !important;
25-
position: absolute !important;
26-
white-space: nowrap !important;
27-
width: 1px !important;
28-
`}
28+
${(props) => props.hideLabel && hidden()}
2929
`;
3030

31-
const ErrorMessage = styled.span`
31+
const ErrorMessage = styled.span<{ hideError: boolean }>`
3232
color: ${color.negative};
3333
font-weight: ${typography.weight.regular};
34+
${(props) => props.hideError && hidden()}
3435
`;
3536

3637
const LabelWrapper = styled.div<{ hideLabel: boolean; error: ReactNode }>`
@@ -143,6 +144,7 @@ interface TextareaProps {
143144
label: string;
144145
appearance?: 'default';
145146
hideLabel?: boolean;
147+
hideError?: boolean;
146148
orientation?: 'vertical' | 'horizontal';
147149
error?: ReactNode | ComponentType;
148150
startFocused?: boolean;
@@ -162,6 +164,7 @@ export const Textarea = forwardRef<
162164
label,
163165
hideLabel = false,
164166
error = null,
167+
hideError = false,
165168
subtext,
166169
subtextSentiment,
167170
appearance = 'default',
@@ -202,7 +205,7 @@ export const Textarea = forwardRef<
202205
{label}
203206
</Label>
204207
{errorMessage && (
205-
<ErrorMessage id={errorId} aria-hidden>
208+
<ErrorMessage hideError={hideError} id={errorId} aria-hidden>
206209
{errorMessage}
207210
</ErrorMessage>
208211
)}

0 commit comments

Comments
 (0)