I am using confirmFilters=true. Right now, customFilterDialogFooter has a button which apply the filters with onClick event however i also want to apply the filters if the user press enter key
Try this.
useEffect(() => {
const ALLOWED_KEYS = ['Enter'] // ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
const handleKeyDown = event => {
const { key } = event
if (ALLOWED_KEYS.includes(key)) {
const applyButton = document.getElementById('<ID-OF-YOUR-BUTTON-HERE>')
if (applyButton) applyButton.click()
}
}
document.addEventListener('keydown', handleKeyDown)
return () => {
document.removeEventListener('keydown', handleKeyDown)
}
}, [])
Try this.
useEffect(() => { const ALLOWED_KEYS = ['Enter'] // ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'] const handleKeyDown = event => { const { key } = event if (ALLOWED_KEYS.includes(key)) { const applyButton = document.getElementById('<ID-OF-YOUR-BUTTON-HERE>') if (applyButton) applyButton.click() } } document.addEventListener('keydown', handleKeyDown) return () => { document.removeEventListener('keydown', handleKeyDown) } }, [])
my guy!!! thank you!
Most helpful comment
Try this.