Skip to content

Commit

Permalink
feat(TextField): add withReadOnlyStyle prop (#1924)
Browse files Browse the repository at this point in the history
  • Loading branch information
talkor authored Feb 5, 2024
1 parent 90cd93a commit 830c613
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/components/TextField/TextField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
overflow: hidden;
text-overflow: ellipsis;
color: var(--primary-text-color);

&.readOnly.withReadOnlyStyle {
background-color: var(--allgrey-background-color);
border: none;
}
}

.textField .inputWrapper .input.inputHover {
Expand Down
12 changes: 10 additions & 2 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ interface TextFieldProps extends VibeComponentProps {
tabIndex?: number;
name?: string;
underline?: boolean;
/**
* Apply new style for read only, use along with `readonly` prop
*/
withReadOnlyStyle?: boolean;
}

const TextField: VibeComponent<TextFieldProps, unknown> & {
Expand Down Expand Up @@ -131,7 +135,8 @@ const TextField: VibeComponent<TextFieldProps, unknown> & {
secondaryDataTestId,
tabIndex,
underline = false,
name
name,
withReadOnlyStyle
},
ref
) => {
Expand Down Expand Up @@ -223,7 +228,10 @@ const TextField: VibeComponent<TextFieldProps, unknown> & {
{/*eslint-disable-next-line jsx-a11y/aria-activedescendant-has-tabindex*/}
<input
className={cx(className, styles.input, {
[styles.inputHasIcon]: !!hasIcon
[styles.inputHasIcon]: !!hasIcon,
[styles.readOnly]: readonly,
// TODO: use `readonly` prop next major instead of withReadOnlyStyle
[styles.withReadOnlyStyle]: withReadOnlyStyle
})}
placeholder={placeholder}
autoComplete={autoComplete}
Expand Down
6 changes: 6 additions & 0 deletions src/components/TextField/__stories__/TextField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export const Overview = {
wrapperClassName: "monday-storybook-text-field_size",
showCharCount: true,
placeholder: "Placeholder text here"
},
parameters: {
controls: {
// TODO: remove exclusion when prop is removed in next major
exclude: ["withReadOnlyStyle"]
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports[`TextField renders correctly when readonly 1`] = `
aria-label=""
aria-owns=""
autoComplete="off"
className="input"
className="input readOnly"
data-testid="text-field_input"
disabled={false}
id="input"
Expand Down

0 comments on commit 830c613

Please sign in to comment.