(key: string)
| 188 | }, [eraFormatter, state.calendar, segment.type]); |
| 189 | |
| 190 | let onInput = (key: string) => { |
| 191 | if (state.isDisabled || state.isReadOnly) { |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | let newValue = enteredKeys.current + key; |
| 196 | |
| 197 | switch (segment.type) { |
| 198 | case 'dayPeriod': |
| 199 | if (startsWith(am, key)) { |
| 200 | state.setSegment('dayPeriod', 0); |
| 201 | } else if (startsWith(pm, key)) { |
| 202 | state.setSegment('dayPeriod', 1); |
| 203 | } else { |
| 204 | break; |
| 205 | } |
| 206 | focusManager.focusNext(); |
| 207 | break; |
| 208 | case 'era': { |
| 209 | let matched = eras.find(e => startsWith(e.formatted, key)); |
| 210 | if (matched) { |
| 211 | state.setSegment('era', matched.era); |
| 212 | focusManager.focusNext(); |
| 213 | } |
| 214 | break; |
| 215 | } |
| 216 | case 'day': |
| 217 | case 'hour': |
| 218 | case 'minute': |
| 219 | case 'second': |
| 220 | case 'month': |
| 221 | case 'year': { |
| 222 | if (!parser.isValidPartialNumber(newValue)) { |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | let numberValue = parser.parse(newValue); |
| 227 | let segmentValue = numberValue; |
| 228 | if (segment.maxValue !== undefined && numberValue > segment.maxValue) { |
| 229 | segmentValue = parser.parse(key); |
| 230 | } |
| 231 | |
| 232 | if (isNaN(numberValue)) { |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | state.setSegment(segment.type, segmentValue); |
| 237 | |
| 238 | if ( |
| 239 | segment.maxValue !== undefined && |
| 240 | (Number(numberValue + '0') > segment.maxValue || |
| 241 | newValue.length >= String(segment.maxValue).length) |
| 242 | ) { |
| 243 | enteredKeys.current = ''; |
| 244 | focusManager.focusNext(); |
| 245 | } else { |
| 246 | enteredKeys.current = newValue; |
| 247 | } |
no test coverage detected