Skip to content

Commit 63595d2

Browse files
fix(DatePicker): readOnlyTextField styles should win over default TextField's (#28891)
* fix(DatePicker): Add more specificity to user provided readOnlyTextField classname to avoid getting its values overriden. * change files * update import * merge classes instead of adding specificity * update comment * update snapshots * Update packages/react/src/components/DatePicker/DatePicker.base.tsx Co-authored-by: Makoto Morimoto <[email protected]> --------- Co-authored-by: Makoto Morimoto <[email protected]>
1 parent 669c13c commit 63595d2

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix(DatePicker): readOnlyTextField styles should win over textfield's default styles.",
4+
"packageName": "@fluentui/react",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react/src/components/DatePicker/DatePicker.base.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { Calendar } from '../../Calendar';
1212
import { FirstWeekOfYear, getDatePartHashValue, compareDatePart, DayOfWeek } from '@fluentui/date-time-utilities';
1313
import { Callout, DirectionalHint } from '../../Callout';
14+
import { mergeStyles } from '../../Styling';
1415
import { TextField } from '../../TextField';
1516
import { FocusTrapZone } from '../../FocusTrapZone';
1617
import { useId, useAsync, useControllableValue } from '@fluentui/react-hooks';
@@ -420,11 +421,14 @@ export const DatePickerBase: React.FunctionComponent<IDatePickerProps> = React.f
420421

421422
const renderReadOnlyInput: ITextFieldProps['onRenderInput'] = inputProps => {
422423
const divProps = getNativeProps(inputProps!, divProperties);
424+
// Need to merge styles so the provided styles win over the default ones. This is due to the classnames having the
425+
// same specificity.
426+
const readOnlyTextFieldClassName = mergeStyles(divProps.className, classNames.readOnlyTextField);
423427

424428
// Talkback on Android treats readonly inputs as disabled, so swipe gestures to open the Calendar
425429
// don't register. Workaround is rendering a div with role="combobox" (passed in via TextField props).
426430
return (
427-
<div {...divProps} className={css(divProps.className, classNames.readOnlyTextField)} tabIndex={tabIndex || 0}>
431+
<div {...divProps} className={readOnlyTextFieldClassName} tabIndex={tabIndex || 0}>
428432
{formattedDate || (
429433
// Putting the placeholder in a separate span fixes specificity issues for the text color
430434
<span className={classNames.readOnlyPlaceholder}>{placeholder}</span>

packages/react/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,19 @@ exports[`DatePicker renders DatePicker with value correctly 1`] = `
331331
box-shadow: none;
332332
box-sizing: border-box;
333333
color: #323130;
334+
cursor: pointer;
334335
font-family: 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif;
335336
font-size: 14px;
336337
font-weight: 400;
338+
height: 32px;
339+
line-height: 30px;
337340
margin-bottom: 0px;
338341
margin-left: 0px;
339342
margin-right: 0px;
340343
margin-top: 0px;
341344
min-width: 0px;
342345
outline: 0px;
346+
overflow: hidden;
343347
padding-bottom: 0;
344348
padding-left: 8px;
345349
padding-right: 24px;
@@ -384,13 +388,6 @@ exports[`DatePicker renders DatePicker with value correctly 1`] = `
384388
@media screen and (-ms-high-contrast: active), screen and (forced-colors: active){&::-ms-input-placeholder {
385389
color: GrayText;
386390
}
387-
{
388-
cursor: pointer;
389-
height: 32px;
390-
line-height: 30px;
391-
overflow: hidden;
392-
text-overflow: ellipsis;
393-
}
394391
data-is-focusable={true}
395392
id="DatePicker0-label"
396393
onBlur={[Function]}
@@ -564,15 +561,19 @@ exports[`DatePicker renders default DatePicker correctly 1`] = `
564561
box-shadow: none;
565562
box-sizing: border-box;
566563
color: #323130;
564+
cursor: pointer;
567565
font-family: 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif;
568566
font-size: 14px;
569567
font-weight: 400;
568+
height: 32px;
569+
line-height: 30px;
570570
margin-bottom: 0px;
571571
margin-left: 0px;
572572
margin-right: 0px;
573573
margin-top: 0px;
574574
min-width: 0px;
575575
outline: 0px;
576+
overflow: hidden;
576577
padding-bottom: 0;
577578
padding-left: 8px;
578579
padding-right: 24px;
@@ -617,13 +618,6 @@ exports[`DatePicker renders default DatePicker correctly 1`] = `
617618
@media screen and (-ms-high-contrast: active), screen and (forced-colors: active){&::-ms-input-placeholder {
618619
color: GrayText;
619620
}
620-
{
621-
cursor: pointer;
622-
height: 32px;
623-
line-height: 30px;
624-
overflow: hidden;
625-
text-overflow: ellipsis;
626-
}
627621
data-is-focusable={true}
628622
id="DatePicker0-label"
629623
onBlur={[Function]}

0 commit comments

Comments
 (0)