Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
panfiva opened this issue Mar 25, 2020 · 7 comments · May be fixed by #5663
Open

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

panfiva opened this issue Mar 25, 2020 · 7 comments · May be fixed by #5663
Labels

Comments

@panfiva
Copy link

panfiva commented Mar 25, 2020

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
@jdemangeon
Copy link
Contributor

Thanks for you issue @panfiva! Can you provide a codesandbox example? So we are able to reproduce.

@panfiva
Copy link
Author

panfiva commented Apr 23, 2020

@fzaninotto
Copy link
Member

Confirmed, thanks.

@aliang
Copy link

aliang commented 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%"
      }
    }
  },
});

@jdemangeon
Copy link
Contributor

jdemangeon commented Aug 24, 2020

Hello @aliang!

It sometimes takes a long time to fix reported issues. However, this repository is open-source and everyone is free to contribute. So, feel free to contribute, your PR is welcome ;)

@AnkitaGupta111
Copy link
Contributor

PR Created: #5663

@fzaninotto fzaninotto linked a pull request Dec 15, 2020 that will close this issue
@panfiva
Copy link
Author

panfiva commented Apr 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants