Skip to content

Commit a288c14

Browse files
authored
Merge pull request #5680 from HSLdevcom/AB#411-timetable-refactor
Ab#411 New date-selector style fixes
2 parents 2e2e042 + af8d258 commit a288c14

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

app/component/date-select-grouped.scss

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
margin-right: 0;
77
background-color: $white;
8-
border: 1px transparent $control-border-color;
8+
border: 1px solid $control-border-color;
99
display: flex;
1010
align-items: center;
1111
border-radius: var(--space-xs);
@@ -18,20 +18,20 @@
1818

1919
.date-select-wrapper--menu-open {
2020
outline: none;
21-
border-color: $primary-color;
21+
border-color: $theme-primary-color;
2222
background: $white;
23-
border: 1px solid $primary-color;
24-
box-shadow: 0 0 3px 0 $secondary-color;
23+
border: 1px solid $theme-primary-color;
24+
box-shadow: 0 0 3px 0 $theme-secondary-color;
2525
border-radius: var(--space-xs);
2626
}
2727

2828
.date-select-wrapper {
2929
&:focus {
3030
outline: none;
31-
border-color: $primary-color;
31+
border-color: $theme-primary-color;
3232
background: $white;
33-
border: 1px solid $primary-color;
34-
box-shadow: 0 0 3px 0 $secondary-color;
33+
border: 1px solid $theme-primary-color;
34+
box-shadow: 0 0 3px 0 $theme-secondary-color;
3535
border-radius: var(--space-xs);
3636
}
3737
}
@@ -86,7 +86,7 @@
8686
line-height: 1.3em;
8787

8888
&:hover {
89-
color: $secondary-color;
89+
color: $theme-secondary-color;
9090
}
9191
}
9292
}
@@ -97,13 +97,13 @@
9797
.route-schedule-grouped__control--menu-is-open {
9898
outline: none;
9999
background: $white;
100-
box-shadow: 0 0 3px 0 $secondary-color;
100+
box-shadow: 0 0 3px 0 $theme-secondary-color;
101101
border-radius: var(--space-xs);
102102
}
103103

104104
.route-schedule-grouped__control--is-focused {
105105
border-radius: var(--space-xs);
106-
box-shadow: 0 0 3px 0 $secondary-color;
106+
box-shadow: 0 0 3px 0 $theme-secondary-color;
107107
}
108108

109109
.route-schedule-grouped__dropdown-indicator {
@@ -116,7 +116,7 @@
116116
margin-right: 0; // control padding provides the gap
117117

118118
.dropdown-arrow {
119-
color: $primary-color;
119+
color: $theme-primary-color;
120120
width: 16px;
121121
height: 16px;
122122
transform-origin: center;
@@ -137,7 +137,6 @@
137137
background: $white;
138138
border: 1px solid $light-gray;
139139
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
140-
max-height: unquote('min(400px, 60vh)');
141140
}
142141

143142
.route-schedule-grouped__menu-list {
@@ -246,7 +245,7 @@
246245
align-items: center;
247246
justify-content: center;
248247
flex-shrink: 0;
249-
color: $primary-color;
248+
color: $theme-primary-color;
250249

251250
svg {
252251
width: 16px;

app/component/stop/DateSelectGrouped.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import React, { useState, useMemo, useCallback } from 'react';
2+
import React, { useState, useMemo, useCallback, useRef } from 'react';
33
import { DateTime } from 'luxon';
44

55
import Select, { components as RSComponents } from 'react-select';
@@ -28,8 +28,25 @@ function DateSelectGrouped({
2828
const GENERATED_DAYS = 60; // Fallback range when no dates provided
2929

3030
const [isMenuOpen, setIsMenuOpen] = useState(false);
31+
const [maxMenuHeight, setMaxMenuHeight] = useState(300);
32+
const selectWrapperRef = useRef(null);
33+
34+
// react-select's internal threshold: opens below when spaceBelow >= this value, otherwise above.
35+
const RS_MIN_MENU_HEIGHT = 140;
36+
const MENU_HEIGHT_FLOOR = 120;
3137

3238
const onMenuOpen = useCallback(() => {
39+
if (selectWrapperRef.current) {
40+
const rect = selectWrapperRef.current.getBoundingClientRect();
41+
const margin = 70;
42+
const spaceBelow = window.innerHeight - rect.bottom - margin;
43+
const spaceAbove = rect.top - margin;
44+
// Mirror react-select's placement decision so maxMenuHeight matches the
45+
// direction the menu will actually open.
46+
const available =
47+
spaceBelow >= RS_MIN_MENU_HEIGHT ? spaceBelow : spaceAbove;
48+
setMaxMenuHeight(Math.max(available, MENU_HEIGHT_FLOOR));
49+
}
3350
setIsMenuOpen(true);
3451
}, []);
3552

@@ -149,6 +166,7 @@ function DateSelectGrouped({
149166

150167
return (
151168
<div
169+
ref={selectWrapperRef}
152170
className={`date-select-wrapper${
153171
isMenuOpen ? ' date-select-wrapper--menu-open' : ''
154172
}`}
@@ -211,6 +229,8 @@ function DateSelectGrouped({
211229
}
212230
value={selectedOption}
213231
menuPlacement="auto"
232+
menuPosition="fixed"
233+
maxMenuHeight={maxMenuHeight}
214234
menuPortalTarget={
215235
typeof document !== 'undefined' ? document.body : null
216236
}

0 commit comments

Comments
 (0)