0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 18:42:40 +00:00

create handler function for controlled input

Moved onChange handler function to a component method and simplified it a smidge.

Must use parseInt now because the input type will change to 'text' rather than 'number'
This commit is contained in:
Gazook89
2024-08-19 22:38:46 -05:00
parent 1196a1577f
commit a42b867bcb
2 changed files with 8 additions and 15 deletions

View File

@@ -231,10 +231,6 @@ const BrewRenderer = (props)=>{
})); }));
}; };
// const handlePageChange = (pageNumber) => {
// // Scroll to the desired page
// scrollToPage(pageNumber);
// };
return ( return (
<> <>

View File

@@ -25,6 +25,10 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
setZoomLevel(zoomChange); setZoomLevel(zoomChange);
}; };
const handlePageChange = (page)=>{
setPageInput((page));
}
return ( return (
<div className='toolBar'> <div className='toolBar'>
<div className='tool'> <div className='tool'>
@@ -79,17 +83,10 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
min={1} min={1}
max={state.totalPages} max={state.totalPages}
id='pageInput' id='pageInput'
value={state.pageNumberInput} value={pageInput}
onChange={(e)=>handleInputChange(e.target.value, 'page')} onChange={(e)=>{
onBlur={(e)=>{ handlePageChange(e.target.value == false ? e.target.value : parseInt(e.target.value));}}
parseInt(state.pageNumberInput) === state.currentPage || onBlur={()=>onPageChange(pageInput)}
onPageChange(parseInt(state.pageNumberInput) - 1);
}}
onKeyPress={(e)=>{
if(e.key === 'Enter') {
e.target.blur();
}
}}
/> />
<div className='tool'> <div className='tool'>