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.

width=100% does not work for List filter text input

See original GitHub issue

What you were expecting: I have a list filter with one field. I am trying to make text input 100% of width as follows. However it still stays the default width.

const useStylesFilterForm = makeStyles({
  form:{ backgroundColor: 'orange'}
})


const PostFilter = (props) => {
  const classes=useStylesFilterForm();
  return (
    <Filter {...props}  classes={classes} >
      <TextInput label="Search 1" source="id" alwaysOn  fullWidth={true}  />
    </Filter>
  );
}

What happened instead: Although form control received MuiFormControl-fullWidth class which set width:100% on the element), the Text Input Element still remained the original size.

Steps to reproduce: Add PostFilter component as filter to any list

Related code: React admin used the following html code to render filter (notice MuiFormControl-fullWidth applied properly)

<form class="RaFilter-form-194 makeStyles-form-191 RaFilterForm-form-195">
<div data-source="id" class="filter-field RaFilterFormInput-body-197">
<div class="MuiFormControl-root MuiTextField-root MuiFormControl-marginDense MuiFormControl-fullWidth">...
.

I was able to force Chrome to render 100% width by adding the following styles:

  • add flex: "1 0 auto" to form div;

  • add width:100% style to the parent div (div data-source=“id”); however i was not able to add this style using properties passed TextInput or Filter components:

const useStylesFilterForm = makeStyles({
  form:{flex: "1 0 auto"},
  formClassName:{backgroundColor:"red", width:"100%"},
  inputComponent:{width:"100%"}
})


const PostFilter = (props) => {
  const classes=useStylesFilterForm();

  return (
    <Filter {...props}  classes={{form:classes.form}} >
      <TextInput
        resettable
        label="Report Search"
        source="search:reportSearch"
        alwaysOn
        fullWidth={true}
        formClassName={classes.formClassName}
        helperText="Helper text"
        className={classes.inputComponent}
        />
    </Filter>
  );
}

Environment

  • React-admin version: 3.3.3
  • Last version that did not exhibit the issue (if applicable):
  • React version: 16.13.1
  • Material UI 4.9.7

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aliangcommented, Jul 10, 2020

I’d love to see a fix for this eventually. Until then, I was able to make the input full-width by applying the styles @panfiva suggested using material-ui’s support for nested styling. It’s fragile, though. See https://material-ui.com/styles/basics/#nesting-selectors

const useFilterStyles = makeStyles({
  form: {
    flex: "1 0 auto",
    '& div[data-source=q]': { // Assumes your TextInput source is `q`
      width: "100%",
      '& div:first-child': {
        width: "100%"
      }
    }
  },
});
0reactions
panfivacommented, Apr 5, 2022

Just tested this issue with 4.0.0-rc.1, and the issue is still present

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML input element not taking 100% width - Stack Overflow
I have input element in page1.html with its css set to 100% thus is expected to fill the width of the view but...
Read more >
[Solved] 100% Width for Email Field and Submit Button
As you can see the email field is wider than the subscribe button. That's because the width of the text input is measured...
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 >
Custom Filtering • reactable - GitHub Pages
reactable( searchMethod = JS(" function(rows, columnIds, filterValue) { /* . ... Tip: Many column filter inputs do not have a visible text label, ......
Read more >
fit-content() - CSS: Cascading Style Sheets - MDN Web Docs
The fit-content() function can also be used as laid out box size for ... grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; ...
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