Skip to content

Commit 4706c44

Browse files
authored
DatePicker bug fixes (#2574)
1 parent 22c301f commit 4706c44

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

packages/@react-aria/datepicker/src/useDateSegment.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {DatePickerFieldState, DateSegment} from '@react-stately/datepicker';
1414
import {DatePickerProps, DateValue} from '@react-types/datepicker';
1515
import {DOMProps} from '@react-types/shared';
16-
import {isIOS, mergeProps, useEvent, useId} from '@react-aria/utils';
16+
import {isIOS, isMac, mergeProps, useEvent, useId} from '@react-aria/utils';
1717
import {labelIds} from './useDateField';
1818
import {NumberParser} from '@internationalized/number';
1919
import React, {HTMLAttributes, RefObject, useMemo, useRef} from 'react';
@@ -101,6 +101,12 @@ export function useDateSegment<T extends DateValue>(props: DatePickerProps<T> &
101101
};
102102

103103
let onKeyDown = (e) => {
104+
// Firefox does not fire selectstart for Ctrl/Cmd + A
105+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1742153
106+
if (e.key === 'a' && (isMac() ? e.metaKey : e.ctrlKey)) {
107+
e.preventDefault();
108+
}
109+
104110
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) {
105111
return;
106112
}

packages/@react-spectrum/datepicker/src/DatePicker.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,19 @@ export function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T
158158
minValue={props.minValue}
159159
maxValue={props.maxValue} />
160160
{showTimeField &&
161-
<TimeField
162-
label="Time"
163-
value={state.timeValue}
164-
onChange={state.setTimeValue}
165-
placeholderValue={timePlaceholder}
166-
granularity={timeGranularity}
167-
minValue={timeMinValue}
168-
maxValue={timeMaxValue}
169-
hourCycle={props.hourCycle}
170-
hideTimeZone={props.hideTimeZone}
171-
marginTop="size-100" />
161+
<div className={classNames(datepickerStyles, 'react-spectrum-Datepicker-timeFields')}>
162+
<TimeField
163+
label="Time"
164+
value={state.timeValue}
165+
onChange={state.setTimeValue}
166+
placeholderValue={timePlaceholder}
167+
granularity={timeGranularity}
168+
minValue={timeMinValue}
169+
maxValue={timeMaxValue}
170+
hourCycle={props.hourCycle}
171+
hideTimeZone={props.hideTimeZone}
172+
marginTop="size-100" />
173+
</div>
172174
}
173175
</Content>
174176
</Dialog>

packages/@react-spectrum/datepicker/src/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
&::-webkit-scrollbar { /* WebKit */
6767
width: 0;
6868
height: 0;
69+
display: none;
6970
}
7071
}
7172

@@ -96,6 +97,12 @@
9697
box-sizing: content-box;
9798
white-space: nowrap;
9899
color: var(--spectrum-textfield-text-color);
100+
101+
&::selection {
102+
/* hide the selection because there is no way to fully prevent it in Firefox */
103+
/* https://bugzilla.mozilla.org/show_bug.cgi?id=1742153 */
104+
background: transparent;
105+
}
99106
}
100107

101108
.react-spectrum-DatePicker-cell:focus {
@@ -149,4 +156,6 @@
149156
width: 100%;
150157
min-width: calc(var(--spectrum-calendar-day-width) * 7);
151158
max-width: calc((var(--spectrum-calendar-day-width) * 7) + (var(--spectrum-calendar-day-padding) * 12));
159+
padding: 0 var(--spectrum-calendar-day-padding);
160+
box-sizing: border-box;
152161
}

0 commit comments

Comments
 (0)