Skip to content

Commit e11a33d

Browse files
committed
css style fixes and replace useEffect
1 parent ccf27a0 commit e11a33d

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

components/dash-core-components/src/components/css/calendar.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
border-radius: 4px;
2020
cursor: default;
2121
user-select: none;
22+
-webkit-user-select: none;
23+
-moz-user-select: none;
2224
width: var(--day-size, 36px);
2325
height: var(--day-size, 36px);
2426
}

components/dash-core-components/src/components/css/datepickers.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
display: block;
33
flex: 1;
44
box-sizing: border-box;
5-
margin: calc(var(--Dash-Spacing) * 2) 0;
5+
background: var(--Dash-Fill-Inverse-Strong);
66
padding: 0;
7-
background: inherit;
87
border: none;
98
outline: none;
109
width: 100%;
@@ -49,11 +48,18 @@
4948
}
5049

5150
.dash-datepicker-input {
52-
height: 34px;
51+
height: 32px;
5352
width: fit-content;
5453
border: none;
5554
outline: none;
5655
border-radius: 4px;
56+
padding: 0;
57+
background-color: inherit;
58+
}
59+
60+
.dash-datepicker-input::selection,
61+
.dash-datepicker-input::-webkit-selection {
62+
background: var(--Dash-Fill-Weak);
5763
}
5864

5965
.dash-datepicker-input-wrapper:focus-within {

components/dash-core-components/src/fragments/DatePickerRange.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,6 @@ const DatePickerRange = ({
148148
}
149149
}, [start_date, internalStartDate, end_date, internalEndDate, updatemode]);
150150

151-
useEffect(() => {
152-
// Keeps focus on the component when the calendar closes
153-
if (!isCalendarOpen) {
154-
if (!startInputValue) {
155-
startInputRef.current?.focus();
156-
} else {
157-
endInputRef.current?.focus();
158-
}
159-
}
160-
}, [isCalendarOpen, startInputValue]);
161-
162151
const sendStartInputAsDate = useCallback(
163152
(focusCalendar = false) => {
164153
if (startInputValue) {
@@ -412,6 +401,24 @@ const DatePickerRange = ({
412401
align="start"
413402
sideOffset={5}
414403
onOpenAutoFocus={e => e.preventDefault()}
404+
onCloseAutoFocus={e => {
405+
e.preventDefault();
406+
// Only focus if focus is not already on one of the inputs
407+
const inputs: (Element | null)[] = [
408+
startInputRef.current,
409+
endInputRef.current,
410+
];
411+
if (inputs.includes(document.activeElement)) {
412+
return;
413+
}
414+
415+
// Keeps focus on the component when the calendar closes
416+
if (!startInputValue) {
417+
startInputRef.current?.focus();
418+
} else {
419+
endInputRef.current?.focus();
420+
}
421+
}}
415422
>
416423
<Calendar
417424
ref={calendarRef}

components/dash-core-components/src/fragments/DatePickerSingle.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ const DatePickerSingle = ({
7777
}
7878
}, [date, internalDate, setProps]);
7979

80-
useEffect(() => inputRef.current?.focus(), [isCalendarOpen]);
81-
8280
const parseUserInput = useCallback(
8381
(focusCalendar = false) => {
8482
if (inputValue === '') {
@@ -207,6 +205,13 @@ const DatePickerSingle = ({
207205
align="start"
208206
sideOffset={5}
209207
onOpenAutoFocus={e => e.preventDefault()}
208+
onCloseAutoFocus={e => {
209+
e.preventDefault();
210+
// Only focus if focus is not already on the input
211+
if (document.activeElement !== inputRef.current) {
212+
inputRef.current?.focus();
213+
}
214+
}}
210215
>
211216
<Calendar
212217
ref={calendarRef}

components/dash-core-components/src/utils/calendar/Calendar.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ const CalendarComponent = ({
294294
>
295295
<div className="dash-datepicker-controls">
296296
<button
297+
type="button"
297298
className="dash-datepicker-month-nav"
298299
onClick={() => changeMonthBy(-1)}
299300
disabled={!canChangeMonthBy(-1)}
@@ -327,6 +328,7 @@ const CalendarComponent = ({
327328
}}
328329
/>
329330
<button
331+
type="button"
330332
className="dash-datepicker-month-nav"
331333
onClick={() => changeMonthBy(1)}
332334
disabled={!canChangeMonthBy(1)}

0 commit comments

Comments
 (0)