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

[Feature Request]: Support button element in UIShell right panel #14236

Open
1 task done
Tracked by #16296
btepe opened this issue Jul 18, 2023 · 2 comments
Open
1 task done
Tracked by #16296

[Feature Request]: Support button element in UIShell right panel #14236

btepe opened this issue Jul 18, 2023 · 2 comments
Labels
component: ui-shell proposal: open This request has gone through triaging. We're determining whether we take this on or not. status: waiting for maintainer response 💬 type: enhancement 💡

Comments

@btepe
Copy link

btepe commented Jul 18, 2023

The problem

The problem we came across is that there is no component that renders a button element and is suitable to be used inside the UIShell side panel. The SwitcherItem component is visually suitable, but always renders a Link element. For actions such as Log out, we need a button element, as it triggers a change in the UI rather then redirecting the user.

Our use-case:
We implemented a header with multiple right panels, as shown in the UI Shell docs. Our panels have different kinds of interactive elements. For instance, we have links to lead the user to relevant documentation or to our terms of use. We also display buttons such as Log out or Delete account that trigger an action.

The workaround we used is to apply the cds--switcher__item class to a ghost Button element. This however creates problems with the button padding and is prone to be broken by changes in the class or button styles with newer versions. I assume this is a fairly common use-case.

The solution

Solution A: The SwitcherItem component could support rendering a Link or Button element. This could be an additional optional prop.

Solution B: There could be an additional component, for instance SidePanelButton or SwitcherAction that renders a button. Since the props are quite different between a link and a button, this might make more sense.

Examples

No response

Application/PAL

No response

Business priority

None

Available extra resources

No response

Code of Conduct

@tay1orjones
Copy link
Member

tay1orjones commented Aug 10, 2023

@btepe The Link component in UIShell has an as prop allowing you to configure this component to render as something other than an anchor tag. Would this work for your use case?

const LinkPropTypes = {
/**
* Provide a custom element or component to render the top-level node for the
* component.
*/
as: PropTypes.elementType,

SwitcherItem spreads additional props via ...rest onto the child Link, so this should be configurable through SwitcherItem as well

<Link
onKeyDown={(evt) => {
setTabFocus(evt);
onKeyDown(evt);
}}
{...rest}

@btepe
Copy link
Author

btepe commented Aug 14, 2023

@tay1orjones I tried this already, but the button styles overwrite some of the SwitcherItem styles. Here is an example:

https://stackblitz.com/edit/carbon-v11-zbmiha?file=src%2FApp.jsx

If you click on the user icon in the header, you'll see a default SwitcherItem, one using a button HTML element and one using the Carbon Button component to render the SwitcherItem. I also added a Button with className="cds--switcher__item". The last one is the current workaround we use, which caused some issues multiple times when the styling of the Button changed in a new Carbon release. This is what they look like:
Screenshot 2023-08-14 at 10 58 39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ui-shell proposal: open This request has gone through triaging. We're determining whether we take this on or not. status: waiting for maintainer response 💬 type: enhancement 💡
Projects
Status: Later 🧊
Development

No branches or pull requests

3 participants