Skip to content

Commit 68c2067

Browse files
committed
fix propTypes
1 parent c3eaf88 commit 68c2067

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

digitransit-component/packages/digitransit-component-autosuggest/src/components/Input.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,20 @@ Input.propTypes = {
7474
getLabelProps: PropTypes.func.isRequired,
7575
clearInput: PropTypes.func.isRequired,
7676
ariaLabel: PropTypes.string.isRequired,
77-
inputRef: PropTypes.oneOfType([
78-
PropTypes.func,
79-
PropTypes.shape({ current: PropTypes.instanceOf(HTMLInputElement) }),
80-
]).isRequired,
77+
inputRef: PropTypes.shape({
78+
current: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
79+
}).isRequired,
8180
styles: PropTypes.objectOf(PropTypes.string).isRequired,
82-
renderLabel: PropTypes.bool.isRequired,
81+
renderLabel: PropTypes.bool,
8382
isMobile: PropTypes.bool.isRequired,
8483
inputClassName: PropTypes.string.isRequired,
85-
transportMode: PropTypes.string.isRequired,
84+
transportMode: PropTypes.string,
8685
clearButtonColor: PropTypes.string.isRequired,
8786
autoFocus: PropTypes.bool,
8887
};
8988

9089
Input.defaultProps = {
9190
autoFocus: false,
91+
renderLabel: false,
92+
transportMode: undefined,
9293
};

digitransit-component/packages/digitransit-component-autosuggest/src/components/MobileView.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const MobileView = ({
4646
inputValue,
4747
setInputValue,
4848
inputClassName,
49+
required,
4950
}) => {
5051
const [t] = useTranslation();
5152
const { lock, unlock } = hooks.useScrollLock();
@@ -158,6 +159,8 @@ const MobileView = ({
158159
clearButtonColor={clearButtonColor}
159160
autoFocus
160161
inputClassName={inputClassName}
162+
required={required}
163+
isMobile
161164
/>
162165
<Suggestions
163166
suggestions={suggestions}
@@ -166,6 +169,7 @@ const MobileView = ({
166169
itemProps={itemProps}
167170
highlightedIndex={highlightedIndex}
168171
isOpen // when mobile view is open we always want to show suggestions
172+
hidden={false}
169173
lng={lng}
170174
styles={styles}
171175
renderClearHistoryButton
@@ -199,19 +203,17 @@ MobileView.propTypes = {
199203
lng: PropTypes.string.isRequired,
200204
color: PropTypes.string,
201205
clearInput: PropTypes.func.isRequired,
202-
isOpen: PropTypes.bool.isRequired,
203206
accessiblePrimaryColor: PropTypes.string.isRequired,
204207
hoverColor: PropTypes.string,
205208
fontWeights: PropTypes.shape({
206-
normal: PropTypes.string,
207-
medium: PropTypes.string,
208-
bold: PropTypes.string,
209+
normal: PropTypes.number,
210+
medium: PropTypes.number,
211+
bold: PropTypes.number,
209212
}).isRequired,
210213
appElement: PropTypes.string.isRequired,
211214
id: PropTypes.string.isRequired,
212215
mobileLabel: PropTypes.string,
213216
clearOldSearches: PropTypes.func.isRequired,
214-
highlightedIndex: PropTypes.number.isRequired,
215217
itemProps: PropTypes.shape({}).isRequired,
216218
suggestions: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
217219
closeHandle: PropTypes.func.isRequired,
@@ -229,6 +231,7 @@ MobileView.propTypes = {
229231
setInputValue: PropTypes.func.isRequired,
230232
renderMobile: PropTypes.bool.isRequired,
231233
inputClassName: PropTypes.string.isRequired,
234+
required: PropTypes.bool.isRequired,
232235
};
233236

234237
MobileView.defaultProps = {

digitransit-component/packages/digitransit-component-autosuggest/src/components/Suggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function Suggestions({
106106
return (
107107
<Suggestion
108108
key={`${suggestion.type}-${
109-
suggestion.properties.id || suggestion.properties.labelId
109+
suggestion.properties.id || suggestion.properties.name
110110
}`}
111111
highlightedIndex={highlightedIndex}
112112
itemIndex={i}

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ function DTAutosuggest({
246246
required,
247247
color,
248248
hoverColor,
249-
inputId,
250249
ariaLabel,
251250
accessiblePrimaryColor,
252251
fontWeights,
@@ -258,19 +257,19 @@ function DTAutosuggest({
258257
...props
259258
}) {
260259
const [t] = useTranslation();
260+
const [shouldRenderMobile, setShouldRenderMobile] = useState(false);
261+
261262
const [suggestions, setSuggestions] = useState([]);
262263
const [valid] = useState(true);
263264
const [isLoading, setLoading] = useState(false);
264-
const [shouldRenderMobile, setShouldRenderMobile] = useState(false);
265-
266265
const [sources, setSources] = useState(props.sources);
267266
const [ownPlaces, setOwnPlaces] = useState(false);
268267
const [pendingSelection, setPendingSelection] = useState(null);
269268

270269
const enterPressedRef = useRef(null);
271270

272271
// create and store input ref in the parent if storeRef is provided
273-
const inputRef = React.useRef(inputId);
272+
const inputRef = React.useRef(id);
274273
useEffect(() => {
275274
if (storeRef) {
276275
storeRef(inputRef.current);
@@ -309,7 +308,7 @@ function DTAutosuggest({
309308
selectItem,
310309
openMenu,
311310
} = useCombobox({
312-
inputId,
311+
inputId: id,
313312
defaultHighlightedIndex: 0,
314313
stateReducer: useCallback(
315314
(state, { type, changes }) => {
@@ -347,6 +346,8 @@ function DTAutosuggest({
347346
};
348347
}
349348
case useCombobox.stateChangeTypes.InputBlur: {
349+
setPendingSelection(null);
350+
setOwnPlaces(false);
350351
if (changes.selectedItem !== undefined) {
351352
const { selectedItem, ...changesWitoutSelection } = changes;
352353
return changesWitoutSelection;
@@ -581,6 +582,7 @@ function DTAutosuggest({
581582
clearButtonColor={color}
582583
accessiblePrimaryColor={accessiblePrimaryColor}
583584
inputClassName={inputClassName}
585+
required={required}
584586
/>
585587
)}
586588

@@ -632,6 +634,8 @@ function DTAutosuggest({
632634
clearButtonColor={color}
633635
placeholder={translatedPlaceholder || t(placeholder, { lng })}
634636
required={required}
637+
transportMode={transportMode}
638+
isMobile={isMobile}
635639
/>
636640

637641
<Suggestions
@@ -699,14 +703,7 @@ DTAutosuggest.propTypes = {
699703
modeSet: PropTypes.string,
700704
// showScroll: PropTypes.bool,
701705
// isEmbedded: PropTypes.bool,
702-
inputId: PropTypes.string.isRequired,
703706
showScroll: PropTypes.bool,
704-
ariaProps: PropTypes.shape({
705-
ariaCurrentSuggestion: PropTypes.string,
706-
ariaRequiredText: PropTypes.string,
707-
SearchBarId: PropTypes.string,
708-
ariaLabelText: PropTypes.string,
709-
}).isRequired,
710707
};
711708

712709
DTAutosuggest.defaultProps = {
@@ -728,7 +725,6 @@ DTAutosuggest.defaultProps = {
728725
color: '#007ac9',
729726
hoverColor: '#0062a1',
730727
accessiblePrimaryColor: '#0074be',
731-
// timeZone: 'Europe/Helsinki',
732728
pathOpts: {
733729
routesPrefix: 'linjat',
734730
stopsPrefix: 'pysakit',

0 commit comments

Comments
 (0)