File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
packages/mui-material/src/Chip Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -531,15 +531,15 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
531531 ...handlers ,
532532 onClick : ( event ) => {
533533 handlers . onClick ?. ( event ) ;
534- onClick ( event ) ;
534+ onClick ?. ( event ) ;
535535 } ,
536536 onKeyDown : ( event ) => {
537537 handlers . onKeyDown ?. ( event ) ;
538- handleKeyDown ( event ) ;
538+ handleKeyDown ?. ( event ) ;
539539 } ,
540540 onKeyUp : ( event ) => {
541541 handlers . onKeyUp ?. ( event ) ;
542- handleKeyUp ( event ) ;
542+ handleKeyUp ?. ( event ) ;
543543 } ,
544544 } ) ,
545545 } ) ;
Original file line number Diff line number Diff line change @@ -733,4 +733,36 @@ describe('<Chip />', () => {
733733 ) . not . to . throw ( ) ;
734734 } ) ;
735735 } ) ;
736+
737+ it ( 'should not throw on clicking Chip when onClick is not provided' , ( ) => {
738+ expect ( ( ) => {
739+ const { getByTestId } = render ( < Chip data-testid = "chip" /> ) ;
740+ const chip = getByTestId ( 'chip' ) ;
741+ fireEvent . click ( chip ) ;
742+ } ) . not . throw ( ) ;
743+ } ) ;
744+
745+ it ( 'should not throw on keydown when onKeyDown is not provided' , ( ) => {
746+ expect ( ( ) => {
747+ const { getByTestId } = render ( < Chip data-testid = "chip" onClick = { ( ) => { } } /> ) ;
748+ const chip = getByTestId ( 'chip' ) ;
749+ act ( ( ) => {
750+ chip . focus ( ) ;
751+ } ) ;
752+
753+ fireEvent . keyDown ( chip , { key : 'Enter' } ) ;
754+ } ) . not . throw ( ) ;
755+ } ) ;
756+
757+ it ( 'should not throw on keyup when onKeyUp is not provided' , ( ) => {
758+ expect ( ( ) => {
759+ const { getByTestId } = render ( < Chip data-testid = "chip" onClick = { ( ) => { } } /> ) ;
760+ const chip = getByTestId ( 'chip' ) ;
761+ act ( ( ) => {
762+ chip . focus ( ) ;
763+ } ) ;
764+
765+ fireEvent . keyUp ( chip , { key : ' ' } ) ;
766+ } ) . not . throw ( ) ;
767+ } ) ;
736768} ) ;
You can’t perform that action at this time.
0 commit comments