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

Allow arrow padding to be configured for a step. #3051

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

JakeThurman
Copy link
Contributor

Hi! First time contributer.

We have a >4px border radius on out shepherd-element, and our looking to increase it so the arrow doesn't overlay the border radius:
image

This PR allows you to configure the arrow padding using something like: arrow: { padding: 10 }

This builds and tests pass locally, please let me know if there's anything else you need from me on this PR, or anything I missed!

Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
shepherd-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 20, 2025 4:43pm

Copy link

vercel bot commented Nov 8, 2024

@JakeThurman is attempting to deploy a commit to the shipshapecode Team on Vercel.

A member of the Team first needs to authorize it.

@JakeThurman
Copy link
Contributor Author

@RobbieTheWagner Any chance this could make it in soon? I'd rather not create an special fork for my company to use, and it sounds like this is important to have for us.

@RobbieTheWagner
Copy link
Member

Hi @JakeThurman apologies for the extremely late reply on this! Is this something that could be fixed via CSS in your app?

We do heavy arrow customization via CSS for our landing page with things like this:

.shepherd-element[data-popper-placement^=top]>.shepherd-arrow {
  bottom:-8px
}

@JakeThurman
Copy link
Contributor Author

JakeThurman commented Jan 28, 2025

@RobbieTheWagner No worries on the delay. I appreciate you taking the time to reply now!

It's certainly possible, but it would only work in isolated cases. floating-ui has lots of logic to make sure the arrow points at the anchor element, and this would eliminate that down to just a fixed number of px from the edge. (i.e., middleware can shift the
tour step 'balloon', but floating UI will adjust the arrow from there.)

This floating-ui padding parameter configures the closest the arrow can get to the edge of the balloon. It seems to be set to 4px because of the default shepherd CSS.

Finally, the floating-ui documentation explicitly says to set this parameter to your border-radius, which is what led me to open this PR so I could do so. See: https://floating-ui.com/docs/arrow#padding

Copy link
Member

@RobbieTheWagner RobbieTheWagner left a comment

Choose a reason for hiding this comment

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

This is great work, thank you for taking this on! I just had a few minor suggestions.

options.middleware.push(
arrow({ element: arrowEl, padding: hasEdgeAlignment ? 4 : 0 })
arrow({ element: arrowEl, padding: hasEdgeAlignment ? arrowOptions.padding : 0 })
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
arrow({ element: arrowEl, padding: hasEdgeAlignment ? arrowOptions.padding : 0 })
arrow({ element: arrowEl, padding: hasEdgeAlignment ? step.options.arrow?.padding ?? 4 : 0 })

What would you think about putting this inline here? I think it is a little less verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work since the existing model allows arrow to be a boolean. (Which I kept to avoid a breaking change). We need to handle the case where step.options.arrow is a boolean which is why I wrote this way I did.

@JakeThurman
Copy link
Contributor Author

Pushed a fixup for the requested changes. I wasn't able to run my updated tests...

I know I did originally when opening this PR, but I couldn't remember how to run them now.
(I tried pnpm run test:ci didn't seem to work -- I got "No projects matched the filters in "C:\projects\shepherd")
Is that the right command?

@RobbieTheWagner
Copy link
Member

@JakeThurman apologies for the delay on this! The commands you will want to run tests are from the root: pnpm test:cy:watch or pnpm test:unit:watch

@JakeThurman
Copy link
Contributor Author

test:cy:watch

Thanks! Updated my fixup to get the tests working.

@RobbieTheWagner
Copy link
Member

Thanks @JakeThurman I think things are looking good now! One final request, could you please update the docs to mention this? The auto generated docs will be updated based on your comments, but we have some hand rolled docs too like https://github.com/shipshapecode/shepherd/blob/main/docs-src/src/content/docs/guides/usage.md#-displaying-arrows

@JakeThurman
Copy link
Contributor Author

Thanks @JakeThurman I think things are looking good now! One final request, could you please update the docs to mention this? The auto generated docs will be updated based on your comments, but we have some hand rolled docs too like main/docs-src/src/content/docs/guides/usage.md#-displaying-arrows

Done. I did a grep and didn't find any other documentation that appeared to need updating.

Comment on lines +214 to +218
const arrowOptions =
typeof step.options.arrow === 'object'
? step.options.arrow
: { padding: 4 };

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const arrowOptions =
typeof step.options.arrow === 'object'
? step.options.arrow
: { padding: 4 };

arrow({ element: arrowEl, padding: hasEdgeAlignment ? 4 : 0 })
arrow({
element: arrowEl,
padding: hasEdgeAlignment ? arrowOptions.padding : 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
padding: hasEdgeAlignment ? arrowOptions.padding : 0
padding: hasEdgeAlignment ? step.options.arrow?.padding ?? 4 : 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! I had responded to this above. This doesn't work since step.options.arrow can still be a boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would be working javascript (I.e., (true).padding is undefined) but typescript doesn't allow that.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, gotcha. Didn't realize TS wouldn't allow it.

@RobbieTheWagner
Copy link
Member

Thanks @JakeThurman! I think my suggestions might have gotten lost from before. I left a couple more, please let me know what you think of them.

@RobbieTheWagner RobbieTheWagner merged commit bd14203 into shipshapecode:main Feb 20, 2025
6 of 7 checks passed
@github-actions github-actions bot mentioned this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants