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/clever-kiwis-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Added `readOnly` prop to `Labelled` component
6 changes: 6 additions & 0 deletions polaris-react/src/components/Labelled/Labelled.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
}
}

.readOnly > .LabelWrapper {
#{$se23} & {
color: var(--p-color-text-subdued);
}
}

.LabelWrapper {
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include text-breakword;
Expand Down
7 changes: 7 additions & 0 deletions polaris-react/src/components/Labelled/Labelled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Label, labelID} from '../Label';
import type {LabelProps} from '../Label';
import {InlineError} from '../InlineError';
import {Text} from '../Text';
import {useFeatures} from '../../utilities/features';

import styles from './Labelled.scss';

Expand All @@ -31,6 +32,8 @@ export interface LabelledProps {
requiredIndicator?: boolean;
/** Labels signify a disabled control */
disabled?: boolean;
/** Labels signify a readOnly control */
readOnly?: boolean;
}

export function Labelled({
Expand All @@ -43,11 +46,15 @@ export function Labelled({
labelHidden,
requiredIndicator,
disabled,
readOnly,
...rest
}: LabelledProps) {
const {polarisSummerEditions2023} = useFeatures();

const className = classNames(
labelHidden && styles.hidden,
disabled && styles.disabled,
polarisSummerEditions2023 && readOnly && styles.readOnly,
);

const actionMarkup = action ? (
Expand Down
29 changes: 24 additions & 5 deletions polaris-react/src/components/TextField/TextField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,31 @@ $spinner-icon-size: 12px;
}
}

.readOnly > .Backdrop {
background-color: var(--p-color-bg-disabled);
.readOnly {
> .Input {
#{$se23} & {
color: var(--p-color-text-subdued);
}
}

#{$se23} & {
// se23 -- specificity bump
> .Backdrop {
background-color: var(--p-color-bg-disabled);

#{$se23} & {
// se23 -- specificity bump
background-color: var(--p-color-bg-transparent-disabled-experimental);
border-color: transparent;
}
}

&.focus {
// stylelint-disable-next-line selector-max-class -- se23
> .Backdrop {
#{$se23} & {
background-color: var(--p-color-bg-transparent-disabled-experimental);
border-color: transparent;
}
}
}
}

Expand All @@ -143,7 +162,7 @@ $spinner-icon-size: 12px;

#{$se23} & {
border: none;
background-color: var(--p-color-bg-disabled);
background-color: var(--p-color-bg-transparent-disabled-experimental);
}
}

Expand Down
1 change: 1 addition & 0 deletions polaris-react/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export function TextField({
helpText={helpText}
requiredIndicator={requiredIndicator}
disabled={disabled}
readOnly={readOnly}
>
<Connected left={connectedLeft} right={connectedRight}>
<div className={className} onClick={handleClick}>
Expand Down