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.

Is there a reason ListItemSecondaryAction is absolutley positioned?

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I just run into #8205 for the nth time and my fix is always the same, make ListItemSecondaryAction staticly positioned, make the list item container a flexbox and undo the additional padding.

        <ListItem
          style={{paddingRight: 16}}
          ContainerProps={{
            style: {display: 'flex', alignItems: 'center'},
          }}
        >
          ...
          <ListItemSecondaryAction
            style={{position: 'static', transform: 'none'}}
          >
            ...
          </ListItemSecondaryAction>
        </ListItem>

It would be nice if this was not necessary and instead the default behavior.

Current Behavior

The ListItemSecondaryAction is absolutely positioned, causing the problem that it does not grow to take the space needed for its content.

Examples

N/A

Context

I think this is described with enough context above.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
rosskevincommented, Dec 6, 2018

I tried this long ago and we merged https://github.com/mui-org/material-ui/pull/5911 but reverted due to the ripple issue.

I did try to revisit this, I still have the branch https://github.com/alienfast/material-ui/tree/list-item-flex-revisited - I tried with a ripple bounding element but I did not have success.

I just bumped into this again - am using a ListItem without button but with secondary actions, and want the content to grow but not overflow the actions. I’ll do something custom for now but I definitely think revisiting this is worthwhile.

1reaction
Jack-Workscommented, Feb 7, 2021

Use a scary method to patch it


    const buttonRef = useRef<HTMLElement>(null)
    const listRef = useRef<HTMLDivElement>(null)
    useLayoutEffect(() => {
        if (!buttonRef.current || !listRef.current) return
        const width = buttonRef.current.getBoundingClientRect().width
        const child = listRef.current.children[0]
        if (!child) return
        ;(child as HTMLElement).style.paddingRight = `${width + 10}px`
    })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a reason ListItemSecondaryAction is absolutley ...
The ListItemSecondaryAction is absolutely positioned, causing the problem that it does not grow to take the space needed for its content.
Read more >
Have two secondary action elements in a list - Stack Overflow
Here are the styles for the secondary action from ListItem: ... to avoid collision as `ListItemSecondaryAction` // is absolutely positioned.
Read more >
[Solved]-Have two secondary action elements in a list-Reactjs
Here are the styles for the secondary action from ListItem: ... Add some space to avoid collision as `ListItemSecondaryAction` // is absolutely positioned....
Read more >
ListItemSecondaryAction API - Material UI - MUI
API reference docs for the React ListItemSecondaryAction component. Learn about the props, CSS, and other APIs of this exported module.
Read more >
Is it also a living hell for you dealing with position absolute?
Position absolute is not tech debt wtf are you goin on about. When an element needs to be absolutely positioned relative to another...
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