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

Invalid prop `actions[0]` supplied to `MaterialTable` and fontSize='small'

Open IraSkyx opened this issue 7 years ago • 18 comments

Describe the bug Warning: Failed prop type: Invalid prop actions[0] supplied to MaterialTable. Can't pass fontSize props when using string icon

To Reproduce Steps to reproduce the behavior:

  1. Add actions to Material Table component Example : actions={[ { icon: 'create', tooltip: 'Add', onClick: (event, rowData) => { //Do stuff } } ]
  2. Instead of a string, pass an icon component directly as the icon props import Create from '@material-ui/icons/Create'; Example : actions={[ { icon: Create, tooltip: 'Add', onClick: (event, rowData) => { //Do stuff } } ]
  3. See error in console
  4. Additionnaly, because of this in m-table-action.js {typeof action.icon === "string" ? ( <Icon {...action.iconProps} fontSize="small">{action.icon}</Icon> ) : ( <action.icon {...action.iconProps} disabled={action.disabled} /> ) } We can't change the fontSize props if the icon is a string, for example if I set iconProps: { fontSize: 'default' } My props will be overriden by the hardcoded one (fontSize="small").

Expected behavior We shouldn't get this warning. You should probably remove this fontSize props to let users customize the size.

Desktop (please complete the following information):

  • Chrome (didn't test on other platforms)
  • Version 1.39.0

IraSkyx avatar Jun 03 '19 00:06 IraSkyx

Hi @IraSkyx

Thanks for clear description. I will resolve this problem asap.

mbrn avatar Jun 05 '19 10:06 mbrn

I am still having this issue - has there been a fix for it yet?

matthewoestreich avatar Jul 22 '19 23:07 matthewoestreich

I am experiencing this issue too. Waiting for fix.

arklanq avatar Jul 24 '19 12:07 arklanq

@IdkMan2 @mbrn FYI--

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}

matthewoestreich avatar Jul 25 '19 13:07 matthewoestreich

@IdkMan2 @mbrn FYI--

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}

I can confirm that. It's working for me too, but it's still a temporary workaround. Waiting for fix from author.

arklanq avatar Jul 25 '19 15:07 arklanq

@IdkMan2 @mbrn FYI--

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}

It clears the warning but it doesn't work with isFreeAction: true unfortunately.

bableves avatar Jul 29 '19 15:07 bableves

@bableves

Nice find. Ultimately this is something that needs to be resolved within the code base. That solution I found could be considered to be hacky. Sorry it's not working for you =/

matthewoestreich avatar Jul 29 '19 15:07 matthewoestreich

@IdkMan2 @mbrn FYI--

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}

Perfect! working for me!

carlosbarlv avatar Sep 26 '19 14:09 carlosbarlv

Having an issue as well. Those actions 'rowData => ({})' works as per row actions just fine, but how to setup a free action?

If i do how it says in docs

actions = [{
            icon: Print,
            tooltip: 'Print',
            isFreeAction: true
          }]

It will render the toolbar icon, but in the same time will throw a warning: Warning: Failed prop type: Invalid prop actions[0] supplied to MaterialTable

Any way to fix it?

skitsanos avatar Nov 04 '19 10:11 skitsanos

Update. it seems that it is obligatory to pass onClick: () =>{} handler to make it work... Solved.

skitsanos avatar Nov 04 '19 10:11 skitsanos

Update. it seems that it is obligatory to pass onClick: () =>{} handler to make it work... Solved.

I'm passing the onClick to these actions yet it doesn't clear the warning.

bableves avatar Nov 04 '19 10:11 bableves

With "material-table": "1.53.0", i have the following for my Material Table:

 components={{
          Toolbar: props => (
            <>
              <MTableToolbar {...props} />
            </>
          )
        }}

actions={[
          {
            icon: () => <Icon className="fas fa-filter" style={{ fontSize: '1rem' }}/>,
            tooltip: 'Filter',
            isFreeAction: true,
            onClick: () =>
            {
            }
          },
          () => ({
            size: 'small',
            tooltip: 'Edit',
            icon: Edit,
            onClick: (event, rowData) =>
            {
              console.log((rowData));
            }
          })
]

First action will be 'table wide' and second one is 'per row'.

You can try it on my sandbox: https://codesandbox.io/s/mui-button-bar-7qcmg

skitsanos avatar Nov 04 '19 11:11 skitsanos

@skitsanos nice work! The root of this problem still needs to be resolved, though (not taking away from your out-of-the-box thinking, but supplying an empty function to "resolve" this feels so hacky)..

Cheers!

matthewoestreich avatar Nov 05 '19 21:11 matthewoestreich

Thank you @oze4

I've done some tweaking to my DataTable wrapper.

Support for URL and array data sources:

data={[id: 1,user: 'demo', email: '[email protected]']}

or

data="http://192.168.1.3/api/users"

Support for two variants of search behavior:

searchVariant="string"

This one will render simple text field where you can type search criteria and look for this value in all fields.

searchVariant="tags"

Allows making search queries by simple or key/value pair tags, for example i can write my search query like this:

demo email:@nowhere.vpn

I've also added EditorDrawer, so when you click on the row, there is a drawer opens where you can deal with your row data:

 rowEditor={(row) =>
                 {
                   console.log(row);
                   return <div>row</div>;
                 }}

Export functionality was modified as well. It can handle custom rendered columns with deep hierarchy of cell data. There is also optional exportAs property on columns that taken into consideration during the export:

columns={[ {
          title: 'Stealth',
          sorting: false,
          render: (row) =>
          {
            if (row.roles.length > 0)
            {
              return '';
            }
            return <span className="far fa-check-circle"/>;
          },
          exportAs: (row) =>
          {
            if (row.roles.length > 0)
            {
              return 'yes';
            }
            return 'no'; 
          }
        }
]}

In this particular case I take role array of my row and render a check icon if array is empty. But for exporting to CSV I render it as yes/no options.

Plus polished some CSS.

To make it work on Edge, add corejs polyfill from https://github.com/zloirock/core-js

import 'core-js/features/array/flat';

demo time

Updated sandbox is here: https://codesandbox.io/s/mui-datatable-7qcmg

You are free to fork and give some love if you find it handy :)

skitsanos avatar Nov 07 '19 14:11 skitsanos

@skitsanos that is awesome!! Excellent work, my friend. I love it :) looks really good, too!

matthewoestreich avatar Nov 08 '19 14:11 matthewoestreich

Thank you for the feedback! I've made few more fixes, i will publish on a codesandbox once @mbrn releases new build.

skitsanos avatar Nov 08 '19 14:11 skitsanos

@mbrn can this be closed?

matthewoestreich avatar May 31 '20 17:05 matthewoestreich

@mbrn can this be closed?

Sure.

mbrn avatar May 31 '20 17:05 mbrn