Skip to content

Commit 0274984

Browse files
committed
fix: support disabled prop in text variant
1 parent 9e9ff38 commit 0274984

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

src/components/experimental/DateField/DateField.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Footer } from '../Field/Footer';
66
import { FakeInput } from '../Field/FakeInput';
77
import { InnerWrapper } from '../Field/InnerWrapper';
88
import { Wrapper } from '../Field/Wrapper';
9-
import { DateInput } from '../Field/Field';
9+
import { DateInput, Input } from '../Field/Field';
1010
import { DateSegment } from '../Field/DateSegment';
1111
import { FieldProps } from '../Field/Props';
1212

@@ -84,12 +84,17 @@ const DateFieldInner = React.forwardRef<HTMLDivElement, DateFieldProps>((props,
8484
{leadingIcon}
8585
<InnerWrapper>
8686
{label && <Label $flying>{label}</Label>}
87-
<input
87+
<Input
8888
ref={inputRef}
8989
value={value}
90-
onChange={e => onChange(e.target.value)}
90+
onChange={e => {
91+
if (isDisabled) return;
92+
onChange(e.target.value);
93+
}}
9194
placeholder={placeholder}
9295
style={inputStyle}
96+
disabled={isDisabled}
97+
aria-disabled={isDisabled}
9398
{...inputProps}
9499
/>
95100
</InnerWrapper>

src/components/experimental/DateField/docs/DateField.stories.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ export const TextVariant: Story = {
9595
}
9696
};
9797

98+
export const TextVariantDisabled: Story = {
99+
args: {
100+
variant: 'text',
101+
placeholder: 'dd / mm / yyyy',
102+
description: 'Text variant should be disabled',
103+
isDisabled: true
104+
},
105+
render: (args: Extract<DateFieldProps, { variant: 'text' }>) => {
106+
const [val, setVal] = React.useState('');
107+
return <DateField {...args} value={val} onChange={setVal} actionIcon={<DropdownSelectIcon />} />;
108+
}
109+
};
110+
98111
export const TextVariantAutoFocus: Story = {
99112
args: {
100113
variant: 'text',

src/components/experimental/DatePicker/DatePicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export function DatePicker(props: DatePickerProps): JSX.Element {
331331
description={description}
332332
errorMessage={errorMessage}
333333
isInvalid={isInvalid}
334+
isDisabled={legacyIsDisabled}
334335
isVisuallyFocused={open}
335336
leadingIcon={<CalendarTodayOutlineIcon />}
336337
value={singleSource ? dateToCalendarDate(singleSource) : undefined}
@@ -362,6 +363,7 @@ export function DatePicker(props: DatePickerProps): JSX.Element {
362363
description={description}
363364
errorMessage={errorMessage}
364365
isInvalid={isInvalid}
366+
isDisabled={legacyIsDisabled || isDisabled}
365367
isVisuallyFocused={open}
366368
leadingIcon={<CalendarTodayOutlineIcon />}
367369
value={inputValue}

src/components/experimental/Field/FakeInput.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const FakeInput = styled.div<{ $isVisuallyFocused: boolean }>`
2424
border-style: solid;
2525
border-color: ${getSemanticValue('outline-variant')};
2626
border-radius: ${get('radii.4')};
27-
2827
min-height: 3.5rem;
2928
padding: 0 ${get('space.3')} 0 ${get('space.4')};
3029
display: flex;
@@ -55,5 +54,11 @@ export const FakeInput = styled.div<{ $isVisuallyFocused: boolean }>`
5554
pointer-events: none;
5655
}
5756
57+
&:has(input[disabled]),
58+
&:has([aria-disabled='true']) {
59+
opacity: 0.38;
60+
pointer-events: none;
61+
}
62+
5863
${props => props.$isVisuallyFocused && focusStyles}
5964
`;

0 commit comments

Comments
 (0)