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.

ReferenceArrayInput ignores withStyles and doesn't have fixed size of width by default

See original GitHub issue

What you were expecting:

either be able to set width with withStyles or it shouldn’t be width: 100%/ display:flex all the time demo here shows chips that wrap: https://github.com/TeamWertarbyte/material-ui-chip-input

What happened instead:

chips are floating left to each other ever-expanding the screen size

Steps to reproduce: Here is a codesandbox that I tried to use withStyles without any result: https://codesandbox.io/s/1oj3j8yj0j - please click on a post and try to add as many tags as possible to see the effect

Related code:

import { withStyles } from '@material-ui/core/styles';


const styles = {
    maxInputSize: {  
        maxWidth: 600,
        width: 600,
    },
};

const MaxWidthReferenceArrayInput =  withStyles(styles)(
    ({ classes, ...props }) => 
    <ReferenceArrayInput label="Tasks" source="tasks" reference="tasks" 
        allowEmpty={true} className={classes.maxInputSize} {...props}>
        <AutocompleteArrayInput optionText="alias" className={classes.maxInputSize}
            options={{ allowDuplicates:false}}/>
    </ReferenceArrayInput>
);

[...]
<MaxWidthReferenceArrayInput/>
[...]

Other information: days ago was posted here as well: https://stackoverflow.com/questions/52915392/how-to-set-maxwidth-in-referencearrayinput

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
eaverdejacommented, Nov 14, 2018

Hey there @zifnab87! I had the same exact problem and stumbled on this issue. I managed a way through it using the classes prop and nested selectors:

import { withStyles } from '@material-ui/core/styles'

const styles = {
    chip: {
        margin: '3px'
    },
    container: {
        '& div': {
            flexWrap: 'wrap',
            marginTop: '18px'
        },
        marginBottom: '8px'
    }
}

export const myAutocompleteArrayInput = withStyles(styles)(({ source, classes }) =>
    <AutocompleteArrayInput
        source={source}
        optionText="nome"
        classes={classes}
    />
)

Hope it also works for you!

2reactions
zifnab87commented, Nov 16, 2018

@eaverdeja this worked great! more specifically I did:

image

const styles = {
    chip: {
        margin: '3px',
    },
    container: {
        '& div': {
            flexWrap: 'wrap',
            marginTop: '18px',
            maxWidth: '400px'
        },
        marginBottom: '8px'
    }
}

export const myAutocompleteArrayInput = withStyles(styles)(({ source, classes }) =>
    <AutocompleteArrayInput
        source={source}
        optionText="nome"
        classes={classes}
    />
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Device width and height in material-ui - css - Stack Overflow
I am using makeStyles() hook, whereas you are using withStyles() , doesn't have any difference between these two.
Read more >
CHANGELOG.md · 邹昊坤/marmelab-react-admin - Gitee.com
Fix <TestContext> doesn't contain notifications node (5659) (fzaninotto); Fix <Filter> fails to show compound filters with no default value (5657) ( ...
Read more >
warning: [antd: form.item] `name` is only used for validate ... - You.com
In 4.0, we adjusted the icon usage API to support tree shaking, reducing the default package size of Antant by about 150 KB...
Read more >
ra-core: Versions - Openbase
Fix <Loading> component doesn't translate messages (#8269) (WiXSL); [Doc] Fix typos ... you will need to set a default value of empty string...
Read more >
UPGRADE.md · 27e446b9cf53340b3fb83f069094db4b3b0a2582 ...
Upgrade to 3.0. We took advantage of the major release to fix all the problems in react-admin that required a breaking change. As...
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