Skip to content

Commit

Permalink
Similar improvement to #324
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebrody committed Nov 2, 2024
1 parent ff8ac89 commit 737872c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions react/src/components/statistic-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ function SelectPage(props: {
}

const curr_universe = useUniverse()

const handleSubmit = (e: React.FocusEvent | React.KeyboardEvent): void => {
let new_page = parseInt((e.target as HTMLInputElement).value)
if (new_page < 1) {
new_page = 1
}
if (new_page > props.max_pages) {
new_page = props.max_pages
}
const new_start = (new_page - 1) * props.per_page + 1
props.change_start(curr_universe, new_start)
}

return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<button onClick={() => { props.change_start(curr_universe, props.prev_page) }} className="serif" style={button_style}>&lt;</button>
Expand All @@ -343,17 +356,11 @@ function SelectPage(props: {
defaultValue={props.current_page}
onKeyDown={(e) => {
if (e.key === 'Enter') {
let new_page = parseInt((e.target as HTMLInputElement).value)
if (new_page < 1) {
new_page = 1
}
if (new_page > props.max_pages) {
new_page = props.max_pages
}
const new_start = (new_page - 1) * props.per_page + 1
props.change_start(curr_universe, new_start)
handleSubmit(e)
}
}}
onFocus={(e) => { e.target.select() }}
onBlur={handleSubmit}
/>
<span>
{' of '}
Expand Down

0 comments on commit 737872c

Please sign in to comment.