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) {
531
531
...handlers ,
532
532
onClick : ( event ) => {
533
533
handlers . onClick ?. ( event ) ;
534
- onClick ( event ) ;
534
+ onClick ?. ( event ) ;
535
535
} ,
536
536
onKeyDown : ( event ) => {
537
537
handlers . onKeyDown ?. ( event ) ;
538
- handleKeyDown ( event ) ;
538
+ handleKeyDown ?. ( event ) ;
539
539
} ,
540
540
onKeyUp : ( event ) => {
541
541
handlers . onKeyUp ?. ( event ) ;
542
- handleKeyUp ( event ) ;
542
+ handleKeyUp ?. ( event ) ;
543
543
} ,
544
544
} ) ,
545
545
} ) ;
Original file line number Diff line number Diff line change @@ -733,4 +733,36 @@ describe('<Chip />', () => {
733
733
) . not . to . throw ( ) ;
734
734
} ) ;
735
735
} ) ;
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
+ } ) ;
736
768
} ) ;
You can’t perform that action at this time.
0 commit comments