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

ActionList.Item: Bug fix to support both inline and block description at the same time #3945

Merged
merged 8 commits into from
Nov 22, 2023

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented Nov 15, 2023

Thanks to ton to @joshblack for his help with the types!! ✨

Found a regression that was introduced in 6 months ago, but hasn't been reported yet :)

To fix that, added a backward compatible "test condition" to slots config, so that the component can be in two different based on props. Only ActionList.Item has this use case with inline and block description.

Example:
Reviewers can have both inline and block description

const [slots, childrenWithoutSlots] = useSlots(props.children, {
      leadingVisual: LeadingVisual,
      trailingVisual: TrailingVisual,
-     description: Description,
+     blockDescription: [Description, props => props.variant === 'block'],
+     inlineDescription: [Description, props => props.variant !== 'block'],
    })
Show code for preview
<ActionList.Item>
  Only I
  <ActionList.Description>inline description</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
  Only B
  <ActionList.Description variant="block">block description</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
  I + B
  <ActionList.Description variant="inline">inline description</ActionList.Description>
  <ActionList.Description variant="block">block description</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
  The everything bagel
  <ActionList.LeadingVisual><StarIcon/></ActionList.LeadingVisual>
  <ActionList.Description variant="inline">inline description</ActionList.Description>
  <ActionList.Description variant="block">block description</ActionList.Description>
  <ActionList.TrailingVisual><StarIcon/></ActionList.TrailingVisual>
</ActionList.Item>
Before After
before: only one of inline or block description is visible after: both inline and block description are visible

See also conversation from slack: https://github.slack.com/archives/C01L618AEP9/p1700085056205969

@siddharthkp siddharthkp requested review from a team and broccolinisoup November 15, 2023 14:59

This comment was marked as resolved.

@siddharthkp siddharthkp self-assigned this Nov 15, 2023
Copy link
Contributor

github-actions bot commented Nov 15, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 104.22 KB (-0.03% 🔽)
dist/browser.umd.js 104.77 KB (-0.03% 🔽)

Copy link
Member Author

Choose a reason for hiding this comment

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

The margin after item was added in Bug fix: ActionList item label weight and spacing if description exists #3490, this was the code:

marginBlockEnd: slots.description && slots.description.props.variant !== 'inline' ? '4px' : undefined,

The intention seems to be to only add margin when description variant !== 'inline', so block description?

I'm not sure if the condition is intentional or not, because the condition would also be true when props.variant is not passed, which defaults to inline (undefined !== 'inline')

I have removed the margin here, tagging @langermank to confirm that was the intention with Bug fix: ActionList item label weight and spacing if description exists #3490

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for tagging me! I think the change you made is correct, mostly just by looking at the snapshots. 🚀

@siddharthkp siddharthkp changed the title Fix ActionList.Item to support both inline and block description at the same time ActionList.Item: Bug fix to support both inline and block description at the same time Nov 15, 2023
@langermank
Copy link
Contributor

Hey @siddharthkp! Before I respond to the margin question, can you clarify how this is a regression? Its my understanding that its one or the other: inline or block. They shouldn't co-exist.. is there a use case I'm not aware of?

@siddharthkp
Copy link
Member Author

siddharthkp commented Nov 16, 2023

Hey @siddharthkp! Before I respond to the margin question, can you clarify how this is a regression? Its my understanding that its one or the other: inline or block. They shouldn't co-exist.. is there a use case I'm not aware of?

When Vini did the initial inventory, we saw a few use cases for it. I remember one clearly because I see it often, but there were a couple more:

Reviewers can have both inline and block description

@@ -36,8 +36,10 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
const [slots, childrenWithoutSlots] = useSlots(props.children, {
leadingVisual: LeadingVisual,
trailingVisual: TrailingVisual,
description: Description,
blockDescription: [Description, props => props.variant === 'block'],
inlineDescription: [Description, props => props.variant !== 'block'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something I don't understand is why not have two different slots for block and inline description? Is it to avoid breaking changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that would be a breaking change. We used to support it before the regression.

But also, this feels like an implementation detail, I don't personally like the idea of it leaking out into the API with ActionList.InlineDescription and ActionList.BlockDescription 😅

@siddharthkp siddharthkp added this pull request to the merge queue Nov 22, 2023
Merged via the queue into main with commit 40b2978 Nov 22, 2023
33 checks passed
@siddharthkp siddharthkp deleted the use-slots-condition branch November 22, 2023 16:19
@primer primer bot mentioned this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants