-1

I'm using office fabric ui DocumentCardActions for my app.but when I click the action button it's not working

<DocumentCard styles={cardStyles} >
   <div className={conversationTileClass}>
      <DocumentCardTitle
          title={selectedInvoice.name}
            shouldTruncate/>
              <DocumentCardTitle title={selectedInvoice.status}
                         shouldTruncate showAsSecondaryTitle/>
             <DocumentCardStatus statusIcon="attach"  />
     </div>
          <DocumentCardActions
                   actions={[
                     {
                        iconProps: { iconName: 'CodeEdit' },
                     onClick:handleEdit(selectedInvoice),
                       ariaLabel: 'share action'
                      },
                    {
                iconProps: { iconName: 'Cancel' },
                 onClick: handleDelete(selectedInvoice.id),
                   ariaLabel: 'pin action'
                    },
                   ]}
                />

and my functions are

const handleDelete =(id)=> {
    console.log(id);
};
function handleEdit (item) {
    console.log(item);
};

1 Answers1

1

Here is codepen with working action buttons: https://codepen.io/vitalius1/pen/pXvyog

<DocumentCardActions
      actions={[
        {
          iconProps: { iconName: 'Share' },
          onClick: this._onClick.bind(this, 'share'),
          ariaLabel: 'share action'
        },
        {
          iconProps: { iconName: 'Pin' },
          onClick: this._onClick.bind(this, 'pin'),
          ariaLabel: 'pin action'
        },
        {
          iconProps: { iconName: 'Ringer' },
          onClick: this._onClick.bind(this, 'notifications'),
          ariaLabel: 'notifications action'
        }
      ]}
      views={432}
/>

private _onClick(action: string, ev:React.SyntheticEvent<HTMLElement>):void {
    alert(`You clicked the ${action} action`);
    ev.stopPropagation();
    ev.preventDefault();
}

It's typescript but I can imagine you can strip most of the stuff and make it JS if you need.

Vitalie Braga
  • 476
  • 2
  • 3