Skip to content

Commit 2e2e042

Browse files
committed
Merge branch 'v3' into next
2 parents ff132ec + 7bf8aae commit 2e2e042

File tree

11 files changed

+176
-214
lines changed

11 files changed

+176
-214
lines changed

config/rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const globals = {
1919
'prop-types': 'PropTypes',
2020
'react-is': 'react-is',
2121
i18next: 'i18next',
22-
'react-autosuggest': 'Autosuggest',
22+
'react-i18next': 'reactI18next',
2323
'react-sortablejs': 'reactSortablejs',
2424
'react-modal': 'ReactModal',
2525
'@hsl-fi/modal': 'Modal',
@@ -49,6 +49,9 @@ const globals = {
4949
'lodash/uniq': 'uniq',
5050
'lodash/compact': 'compact',
5151
'react-relay': 'reactRelay',
52+
downshift: 'downshift',
53+
luxon: 'luxon',
54+
'react-select': 'Select',
5255
};
5356

5457
async function getSortedPackages() {

digitransit-component/packages/digitransit-component-autosuggest-panel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@digitransit-component/digitransit-component-autosuggest-panel",
3-
"version": "8.1.3",
3+
"version": "8.2.0",
44
"description": "digitransit-component autosuggest-panel module",
55
"main": "index.js",
66
"files": [

digitransit-component/packages/digitransit-component-autosuggest-panel/src/helpers/Select.js

Lines changed: 55 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,79 @@
11
import PropTypes from 'prop-types';
2-
import React, { useState, useEffect, useRef, useLayoutEffect } from 'react';
3-
import Autosuggest from 'react-autosuggest';
2+
import cx from 'classnames';
3+
import React from 'react';
4+
import { useSelect } from 'downshift';
45
import styles from './select.scss';
56

67
const Select = ({
78
value,
8-
getDisplay,
99
options,
1010
onSlackTimeSelected,
1111
viaPointIndex,
1212
id,
1313
label,
1414
icon,
1515
}) => {
16-
const [displayValue, changeDisplayValue] = useState(getDisplay(value));
17-
const [open, changeOpen] = useState(false);
18-
useEffect(() => changeDisplayValue(getDisplay(value)), [value]);
19-
const scrollRef = useRef(null);
20-
const scrollIndex = Math.floor(value / 600);
21-
const elementHeight = 50;
22-
useLayoutEffect(() => {
23-
if (open && scrollRef.current) {
24-
scrollRef.current.scrollTop = elementHeight * scrollIndex;
25-
}
26-
}, [value, open]);
27-
28-
const inputId = `${id}-input`;
2916
const labelId = `${id}-label`;
17+
const selectedItem = options.find(option => option.value === value);
18+
19+
const {
20+
isOpen,
21+
getToggleButtonProps,
22+
getMenuProps,
23+
getItemProps,
24+
getLabelProps,
25+
highlightedIndex,
26+
} = useSelect({
27+
selectedItem,
28+
items: options,
29+
labelId,
30+
id,
31+
itemToString: item => item.displayName,
32+
onSelectedItemChange: ({ selectedItem: newItem }) => {
33+
onSlackTimeSelected(newItem.value, viaPointIndex);
34+
},
35+
});
3036

31-
const onInputChange = (_, { newValue, method }) => {
32-
switch (method) {
33-
case 'enter':
34-
case 'click':
35-
onSlackTimeSelected(newValue, viaPointIndex);
36-
break;
37-
case 'escape':
38-
changeDisplayValue(value);
39-
break;
40-
case 'up':
41-
case 'down':
42-
default:
43-
break;
44-
}
45-
};
4637
return (
47-
<label className={styles['combobox-container']} htmlFor={inputId}>
48-
<span className={styles['left-column']}>
49-
<span className={styles['combobox-label']} id={labelId}>
50-
{label}
51-
</span>
52-
<Autosuggest
53-
id={id}
54-
suggestions={options}
55-
getSuggestionValue={s => s.value}
56-
renderSuggestion={s => s.displayName}
57-
onSuggestionsFetchRequested={() => null}
58-
shouldRenderSuggestions={() => true}
59-
focusInputOnSuggestionClick={false}
60-
onSuggestionsClearRequested={() => null}
61-
inputProps={{
62-
value: displayValue,
63-
onChange: onInputChange,
64-
onFocus: () => {
65-
changeOpen(true);
66-
},
67-
onBlur: () => {
68-
changeOpen(false);
69-
},
70-
id: inputId,
71-
'aria-labelledby': labelId,
72-
'aria-autocomplete': 'none',
73-
readOnly: true,
74-
}}
75-
renderSuggestionsContainer={({ containerProps, children }) => {
76-
// set refs for autosuggest library and scrollbar positioning
77-
const { ref, ...otherRefs } = containerProps;
78-
const containerRef = elem => {
79-
if (elem) {
80-
scrollRef.current = elem;
81-
ref(elem);
82-
}
83-
};
84-
return (
85-
<div tabIndex="-1" {...otherRefs} ref={containerRef}>
86-
{children}
87-
</div>
88-
);
89-
}}
90-
theme={styles}
91-
/>
92-
</span>
93-
{icon}
94-
</label>
38+
<div className={styles['combobox-container']}>
39+
<div className={styles.container}>
40+
<div {...getToggleButtonProps()}>
41+
<span className={styles['left-column']}>
42+
<label {...getLabelProps()} className={styles['combobox-label']}>
43+
{label}
44+
</label>
45+
<div className={styles.input}>
46+
<span>{selectedItem.displayName}</span>
47+
</div>
48+
</span>
49+
{icon}
50+
</div>
51+
<ul
52+
className={cx([styles.suggestionsContainerOpen, !isOpen && 'hidden'])}
53+
{...getMenuProps()}
54+
>
55+
{isOpen &&
56+
options.map((option, index) => (
57+
<li
58+
key={option.value}
59+
className={cx([
60+
styles.suggestion,
61+
index === highlightedIndex && styles.suggestionHighlighted,
62+
])}
63+
{...getItemProps({ index })}
64+
>
65+
<span>{option.displayName}</span>
66+
</li>
67+
))}
68+
</ul>
69+
</div>
70+
</div>
9571
);
9672
};
9773

9874
Select.propTypes = {
9975
value: PropTypes.number.isRequired,
10076
onSlackTimeSelected: PropTypes.func.isRequired,
101-
getDisplay: PropTypes.func.isRequired,
10277
options: PropTypes.arrayOf(
10378
PropTypes.shape({
10479
displayName: PropTypes.string.isRequired,

digitransit-component/packages/digitransit-component-autosuggest-panel/src/helpers/select.scss

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ $zindex: base, map-container, map-gradient, map-fullscreen-toggle, map-buttons,
4141

4242
.container {
4343
position: relative;
44+
width: 100%;
45+
height: 100%;
46+
47+
> div {
48+
display: flex;
49+
align-items: center;
50+
justify-content: space-between;
51+
width: 100%;
52+
height: 100%;
53+
cursor: pointer;
54+
}
4455

4556
.suggestion {
4657
font-size: 15px;
@@ -68,8 +79,13 @@ $zindex: base, map-container, map-gradient, map-fullscreen-toggle, map-buttons,
6879
border-radius: 5px;
6980
box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.06);
7081
border: 1px rgba(0, 0, 0, 0.1) solid;
71-
top: 35px;
72-
width: calc(100% + 45px); // 43px == width of icon next to input
82+
top: calc(100% + 4px);
83+
left: 0;
84+
width: 100%;
85+
list-style-type: none;
86+
padding: 0;
87+
margin: 0;
88+
7389
ul {
7490
padding: 0;
7591
margin: 0;

digitransit-component/packages/digitransit-component-autosuggest-panel/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ class DTAutosuggestPanel extends React.Component {
606606
label={t('viapoint-slack-amount', { lng })}
607607
options={slackTime}
608608
value={getViaPointSlackTimeOrDefault(viaPoints[i])}
609-
getDisplay={this.getSlackDisplay}
610609
viaPointIndex={i}
611610
icon={
612611
<span

digitransit-component/packages/digitransit-component-datetimepicker/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@digitransit-component/digitransit-component-datetimepicker",
3-
"version": "5.0.1",
3+
"version": "6.0.0",
44
"description": "digitransit-component datetimepicker module",
55
"main": "index.js",
66
"files": [
@@ -31,13 +31,13 @@
3131
"peerDependencies": {
3232
"@digitransit-component/digitransit-component-icon": "^2.0.1",
3333
"classnames": "2.5.1",
34+
"downshift": "9.0.10",
3435
"i18next": "^22.5.1",
3536
"lodash": "4.17.23",
3637
"lodash-es": "4.17.23",
3738
"luxon": "^3.6.1",
3839
"prop-types": "^15.8.1",
3940
"react": "^16.13.0",
40-
"react-autosuggest": "^10.0.0",
4141
"react-i18next": "^12.3.1",
4242
"react-modal": "~3.11.2",
4343
"react-select": "5.8.0"

0 commit comments

Comments
 (0)