Skip to content

Commit 18e3632

Browse files
author
Wojciech Maj
committed
Fix jumping to previous/next input not working if leading zeros were present
1 parent 96c8c13 commit 18e3632

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/DateInput.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,22 @@ const getDetailValueArray = (value, minDate, maxDate, maxDetail) => {
110110
];
111111
};
112112

113+
const isValidInput = element => element.tagName === 'INPUT' && element.type !== 'date';
114+
113115
const findPreviousInput = (element) => {
114-
const previousElement = element.previousElementSibling; // Divider between inputs
115-
if (!previousElement) {
116-
return null;
117-
}
118-
return previousElement.previousElementSibling; // Actual input
116+
let previousElement = element;
117+
do {
118+
previousElement = previousElement.previousElementSibling;
119+
} while (previousElement && !isValidInput(previousElement));
120+
return previousElement;
119121
};
120122

121123
const findNextInput = (element) => {
122-
const nextElement = element.nextElementSibling; // Divider between inputs
123-
if (!nextElement) {
124-
return null;
125-
}
126-
return nextElement.nextElementSibling; // Actual input
124+
let nextElement = element;
125+
do {
126+
nextElement = nextElement.nextElementSibling;
127+
} while (nextElement && !isValidInput(nextElement));
128+
return nextElement;
127129
};
128130

129131
const focus = element => element && element.focus();

0 commit comments

Comments
 (0)