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