question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When using a custom TextField component, properties to not filter down to the component.

See original GitHub issue

I am working on 2.2.4 of npm

I am trying to create a custom Material-UI input component that incorporates all the different input controls as well as custom theme and styling. When trying to apply the pickers, everything works fine for the standard pickers, but when I try to use an inline picker, the props that are supposed to filter down to the text field are being omitted from the properties.

  1. I created a component that extends Input. Call it InputEx.

  2. This component expects a few custom properties, let’s say “backColor” is one.

  3. In my primary components render, I do this: component = <DatePicker backColor="#ff00ff" TextFieldComponent={InputEx} {...AllOtherNormalProps}/>

  4. When I render “component” my InputEx recieves the backColor property normally and everything is good.

  5. If I switch it up and use an inline component instead, the backColor property is not passed to the InputEx component. component = <InlineDatePicker backColor="#ff00ff" TextFieldComponent={InputEx} {...AllOtherNormalProps}/>

Now, I have gone through the source code and I can’t figure out what is going on exactly, as it looks like it should be doing exactly what it should. However, when I go through the node_modules code, I find this:

node_modules\material-ui-pickers\DatePicker\DatePickerInline.js line 39 (near the end of the line with the definition of the other variable)

other = __rest(props, [ "allowKeyboardControl", "animateYearScrolling", "disableFuture", "disablePast", "format", "forwardedRef", "labelFunc", "leftArrowIcon", "maxDate", "minDate", "initialFocusedDate", "onChange", "openToYearSelection", "renderDay", "rightArrowIcon", "shouldDisableDate", "value", "autoOk", "onlyCalendar", "views", "openTo" ]);

Now, I am not an expert and I could be very very wrong here, but it looks like the “other” variant that should be populated with all the, well, other properties to be passed to the text field component are being limited to those specific properties listed, and as such, any property not in the list is omitted. But I can’t figure out how to fix this in the primary typeScript source.

I am kind of stuck. Any idea how I can get an inline component to pass the custom properties to the text field component?

PS: I have been going through the “next” branch and I can see there are quite a few changes being done, so this issue may not actually be an issue anymore. But if anyone can drop a line as to how to fix this for the current version, That’ll be great.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dave-educodecommented, Apr 10, 2019

I have a my input component in a wrapper which is then passed into the datepicker which is then wrapped in a styled component. I need to filter the custom props before I pass them into the material-ui input or I get errors in the console about properties and I was filtering my custom props on the wrong wrapper. Basically, I glorified typo. I’m apologize for bringing it up here.

0reactions
mmlumbacommented, Apr 9, 2019

@dave-educode what was the problem you mentioned in your latest comment? I’m experiencing this similar issue and would like some insight

Read more comments on GitHub >

github_iconTop Results From Across the Web

When using a custom TextField component, properties to not ...
I am working on 2.2.4 of npm I am trying to create a custom Material-UI input component that incorporates all the different input...
Read more >
In React ES6, why does the input field lose focus after typing a ...
I had a similar issue when using styled-components inside a functional component. The custom input element was losing focus every time I typed...
Read more >
Input Components - React-admin - Marmelab
An Input component displays an input, or a dropdown list, a list of radio buttons, etc. Such components allow to update a record...
Read more >
React Autocomplete component - Material UI - MUI
The component exposes a factory to create a filter method that can be provided to the filterOptions prop. You can use it to...
Read more >
9 Using Input Components and Defining Forms
Most input components also have the capability of displaying only the label, and not appearing capable of changing value until the user mouses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found