File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
packages/module/src/SourcesCard Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -242,4 +242,18 @@ describe('SourcesCard', () => {
242242 ) ;
243243 expect ( screen . getByRole ( 'region' ) ) . toHaveAttribute ( 'class' , 'pf-v6-c-expandable-section__content' ) ;
244244 } ) ;
245+
246+ it ( 'should call onClick appropriately' , async ( ) => {
247+ const spy = jest . fn ( ) ;
248+ render ( < SourcesCard sources = { [ { title : 'How to make an apple pie' , link : '' , onClick : spy } ] } /> ) ;
249+ await userEvent . click ( screen . getByRole ( 'link' , { name : / H o w t o m a k e a n a p p l e p i e / i } ) ) ;
250+ expect ( spy ) . toHaveBeenCalled ( ) ;
251+ } ) ;
252+
253+ it ( 'should apply titleProps appropriately' , ( ) => {
254+ render (
255+ < SourcesCard sources = { [ { title : 'How to make an apple pie' , link : '' , titleProps : { className : 'test' } } ] } />
256+ ) ;
257+ expect ( screen . getByRole ( 'link' , { name : / H o w t o m a k e a n a p p l e p i e / i } ) ) . toHaveClass ( 'test' ) ;
258+ } ) ;
245259} ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { useState } from 'react';
66// Import PatternFly components
77import {
88 Button ,
9+ ButtonProps ,
910 ButtonVariant ,
1011 Card ,
1112 CardBody ,
@@ -31,11 +32,20 @@ export interface SourcesCardProps extends CardProps {
3132 paginationAriaLabel ?: string ;
3233 /** Content rendered inside the paginated card */
3334 sources : {
35+ /** Title of sources card */
3436 title ?: string ;
37+ /** Link to source */
3538 link : string ;
39+ /** Body of sources card */
3640 body ?: React . ReactNode | string ;
41+ /** Whether link is external */
3742 isExternal ?: boolean ;
43+ /** Whether sources card is expandable */
3844 hasShowMore ?: boolean ;
45+ /** onClick event applied to the title of the Sources card */
46+ onClick ?: React . MouseEventHandler < HTMLButtonElement > ;
47+ /** Any additional props applied to the title of the Sources card */
48+ titleProps ?: ButtonProps ;
3949 } [ ] ;
4050 /** Label for the English word "source" */
4151 sourceWord ?: string ;
@@ -107,6 +117,8 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
107117 isInline
108118 rel = { sources [ page - 1 ] . isExternal ? 'noreferrer' : undefined }
109119 target = { sources [ page - 1 ] . isExternal ? '_blank' : undefined }
120+ onClick = { sources [ page - 1 ] . onClick ?? undefined }
121+ { ...sources [ page - 1 ] . titleProps }
110122 >
111123 { renderTitle ( sources [ page - 1 ] . title ) }
112124 </ Button >
You can’t perform that action at this time.
0 commit comments