material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[base][Input] inputProps onKeyDown is not working

Open ysds opened this issue 1 year ago • 4 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/broken-cookies-k6px3x?file=/demo.tsx:1459-1539

Steps:

  1. Enter text to the input
  2. "onKeyDown" is not output to the console log

Current behavior 😯

onKeyDown is not triggered

Expected behavior 🤔

onKeyDown is triggered

Context 🔦

I forget the specific version, but onKeyDown used to work before, but does not seem to work now. Is this an expected specification?

Your environment 🌎

npx @mui/envinfo
  Please see the codesandbox dependencies

ysds avatar May 02 '23 11:05 ysds

@ysds Thanks for reporting this 🙂

onKeyDown as a normal prop (not through slotProps) will work

<CustomInput
  aria-label="Demo input"
  placeholder="Type something…"
  onKeyDown={() => console.log('props onKeyDown')}
/>

Here is a working sandbox: https://codesandbox.io/s/https-github-com-mui-material-ui-issues-37134-vxjbpy?file=/demo.tsx

mj12albert avatar May 02 '23 12:05 mj12albert

Should we allow both to work 🤔 ? CC @michaldudak @mui/core

mj12albert avatar May 02 '23 12:05 mj12albert

since onChange when set from slotProps is working, i think other even handlers should also work. or else developers will have hard time figuring out which are working and which aren't. what do you think?

sai6855 avatar May 02 '23 12:05 sai6855

Should we allow both to work 🤔 ?

Yes, definitely.

michaldudak avatar May 02 '23 20:05 michaldudak

@sai6855 are you working on this? If not, could you please assign this to me?

nicolas-ot avatar May 09 '23 12:05 nicolas-ot

@nicolas-ot ah yes I'm planning to work on this

sai6855 avatar May 09 '23 13:05 sai6855