0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-28 00:32:42 +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 (
<>

View File

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