Skip to content

Commit 4ec1b6c

Browse files
fix: address code review feedback - improve type safety and React best practices
1 parent 1488d2a commit 4ec1b6c

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/Options.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,10 @@ const Options: React.FC<OptionsProps> = (props) => {
6060
: (value: string | number) => `${value} ${locale.items_per_page}`;
6161

6262
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
63-
let value = e.target.value;
64-
63+
const value = e.target.value;
6564
// Filter non-numeric characters for QuickJumper input
6665
const numericValue = value.replace(/\D/g, '');
67-
if (numericValue !== value) {
68-
e.target.value = numericValue;
69-
value = numericValue;
70-
}
71-
72-
setGoInputText(value);
66+
setGoInputText(numericValue);
7367
};
7468

7569
const handleBlur = (e: React.FocusEvent<HTMLInputElement, Element>) => {

src/Pagination.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
148148
function getValidValueForFiltered(
149149
originalValue: string,
150150
filteredValue: string,
151-
): number {
151+
): number | '' {
152152
// If the input was completely filtered out (non-numeric), return current value
153153
if (filteredValue === '' && originalValue !== '') {
154154
return internalInputVal;
@@ -187,19 +187,22 @@ const Pagination: React.FC<PaginationProps> = (props) => {
187187
}
188188

189189
const value = getValidValueForFiltered(originalValue, numericValue);
190-
if (value !== internalInputVal) {
191-
setInternalInputVal(value);
190+
// Handle empty string case
191+
const numValue = typeof value === 'number' ? value : internalInputVal;
192+
193+
if (numValue !== internalInputVal) {
194+
setInternalInputVal(numValue);
192195
}
193196

194197
switch ((event as React.KeyboardEvent<HTMLInputElement>).keyCode) {
195198
case KeyCode.ENTER:
196-
handleChange(value);
199+
handleChange(numValue);
197200
break;
198201
case KeyCode.UP:
199-
handleChange(value - 1);
202+
handleChange(numValue - 1);
200203
break;
201204
case KeyCode.DOWN:
202-
handleChange(value + 1);
205+
handleChange(numValue + 1);
203206
break;
204207
default:
205208
break;

0 commit comments

Comments
 (0)