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

When using a React.Element as title for columns, The editable placeholder renders as "Object"

Open masbaehr opened this issue 7 years ago • 6 comments

When using a complex title instead of a simple string this happens:

Title is defined as: title?: string | React.ReactElement;

Exemplary code

  columns={[
                
                { title: <div>Italiano (chiave)<img style={flagstyle} src='whatever.png'></img></div>, field: 'it' }

image

Warning: Failed prop type: Invalid prop placeholder of type object supplied to ForwardRef(InputBase), expected string. in ForwardRef(InputBase) (created by WithStyles(ForwardRef(InputBase))) in WithStyles(ForwardRef(InputBase)) (created by ForwardRef(Input)) in ForwardRef(Input) (created by WithStyles(ForwardRef(Input)))

masbaehr avatar Oct 27 '19 07:10 masbaehr

I don't think the issue is on the title, I think it has to do with the data. My guess is that maybe instead of passing a string value, you're passing an object. What else do you have in columns?

jonasanx avatar Oct 30 '19 21:10 jonasanx

The issue is on the title, as i have tested to just type "whatever" then it renders correctly. Basically the title is used as a placeholder internally causing the error. However a ReactElement is allowed to be used as a title e.g. if you want to render something else other than a plain string. Maybe something called "editPlaceholder" would be a nicer way to solve the problem. Then you can specify something like "Type new value..."

masbaehr avatar Oct 30 '19 21:10 masbaehr

This problem is not resolved? ReactElement in title is possible, but not in the crap placeholder. But for the placeholder, the value is taken from the title

WinZip17 avatar Nov 06 '19 16:11 WinZip17

Then the proper way to solve this would be to allow a ReactElement for title and a String for "titlePlaceholder" ;) The way it is now, is not correct and definitely buggy or at least error-prone

masbaehr avatar Nov 06 '19 20:11 masbaehr

Suggestion for fixing this issue properly. I'm sorry for not providing a pull request but i don't have the proficiency to know if this is enough or not. But it should be a reasonable solution which should not break current implementation by providing additional functionality

In m-table-edit-field.js

Instead of :

 placeholder={this.props.columnDef.title} 

use:

 placeholder={(typeof this.props.columnDef.title !== 'string') ? this.props.columnDef.placeholder : this.props.columnDef.title}

Then in the column definition the following would be possible:

    { title: <div>Key<MdiIcons.Key style={{marginLeft: 5, verticalAlign: "bottom", color: "gray"}}></MdiIcons.Key></div>, field: keyIso, placeholder: "Key" },

masbaehr avatar Feb 07 '20 08:02 masbaehr

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Jul 05 '20 22:07 stale[bot]