Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix overflowing focus outline for `Grid` items for Teams theme @Bugaa92 ([#1195](https://github.com/stardust-ui/react/pull/1195))
- Fix routing for accessibility documentation @sophieH29 ([#1208](https://github.com/stardust-ui/react/pull/1208))
- Fix `content` prop type in `Dialog` @layershifter ([#1212](https://github.com/stardust-ui/react/pull/1212))
- Add `keyboard` up & down key controls for the `Tree` component @priyankar205 ([#1219]https://github.com/stardust-ui/react/pull/1219)
- Add `keyboard` up & down key controls for the `Tree` component @priyankar205 ([#1219](https://github.com/stardust-ui/react/pull/1219))
- Simplify DOM structure in `List` component when not all slot are defined @layershifter ([#1218](https://github.com/stardust-ui/react/pull/1218))

### Features
- Add `Embed` and `Video` components @stuartlong ([#1108](https://github.com/stardust-ui/react/pull/1108))
Expand Down
34 changes: 25 additions & 9 deletions packages/react/src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class ListItem extends UIComponent<ReactProps<ListItemProps>, ListItemState> {
_.invoke(this.props, 'onFocus', e, this.props)
}

wrapWithFlex = (part: React.ReactNode, shouldWrap: boolean) =>
shouldWrap ? <Flex gap="gap.smaller">{part}</Flex> : part

renderComponent({ classes, accessibility, unhandledProps, styles }) {
const { as, debug, endMedia, media, content, contentMedia, header, headerMedia } = this.props

Expand Down Expand Up @@ -175,6 +178,24 @@ class ListItem extends UIComponent<ReactProps<ListItemProps>, ListItemState> {
},
})

const hasHeaderPart = headerElement || headerMediaElement
const headerPart = hasHeaderPart && (
<>
<Flex.Item grow>{headerElement}</Flex.Item>
{headerMediaElement}
</>
)

const hasContentPart = contentElement || contentMediaElement
const contentPart = hasContentPart && (
<>
<Flex.Item grow>{contentElement}</Flex.Item>
{contentMediaElement}
</>
)

const hasBothParts = hasContentPart && hasHeaderPart

return (
<Flex
vAlign="center"
Expand All @@ -189,16 +210,11 @@ class ListItem extends UIComponent<ReactProps<ListItemProps>, ListItemState> {
{...applyAccessibilityKeyHandlers(accessibility.keyHandlers.root, unhandledProps)}
>
{mediaElement}

<Flex.Item grow>
<Flex column className={ListItem.slotClassNames.main} styles={styles.main}>
<Flex gap="gap.smaller">
<Flex.Item grow>{headerElement}</Flex.Item>
{headerMediaElement}
</Flex>
<Flex gap="gap.smaller">
<Flex.Item grow>{contentElement}</Flex.Item>
{contentMediaElement}
</Flex>
<Flex column={hasBothParts} className={ListItem.slotClassNames.main} styles={styles.main}>
{this.wrapWithFlex(headerPart, hasBothParts)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting after this was merged. Why we have confition for adding Flex if the content and header parts exists, when the Flex we are using are adding gap between the element + mediaElement. With this we have regression (the gap between header + headerMedia and content + contentMedia are incorrect if the header and content are not applied both..).

Previous:
image

Current:
image

{this.wrapWithFlex(contentPart, hasBothParts)}
</Flex>
</Flex.Item>
{endMediaElement}
Expand Down