Skip to content

Conversation

@cchaos
Copy link
Contributor

@cchaos cchaos commented Jul 13, 2021

Style updates

Before, both the default and Amsterdam themes had the same styling: a simple bordered-on-hover-only item.

image

Now, the Amsterdam version is more aligned to the designs from Figma and I've added an isSelected prop for indicating current items. I also increased the contrast of the text as the subdued color was too subdued for such large (possible primary) menu items and when the icons inherit their color.

AFTER:

image

Checkable

Closes #4000

Adds checkable = 'multi' | 'single' to the EuiKeyPadMenuItem component

When multi, will display as a checkbox and when single will display as a radio (on hover & selected). It changes the consumer's required interaction prop from onClick to onChange and uses isSelected to chance the checked status.

image

Adds checkable prop to EuiKeyPadMenu for wrapping the group as a <fieldset>

Originally I thought to just showcase it being wrapped in an EuiFormRow, but it comes with too much baggage. Therefore, it just allows consumers to pass either:

  • true: Just renders the <fieldset> and requires consumers to still pass in their own labelling via any method they like
  • { legend | ariaLegend }: Where ariaLegend is just a string applied to arial-label of the fieldset for a visibly hidden legend. They can further customize the <legend> with legendProps.

This creates the proper accessibility hook-ups.

Other

I also fixed up some styling associated with the beta badge to strictly use the new EuiBetaBadge props.

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for the any docs examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

@cchaos cchaos changed the title [EuiKeyPadMenuItem] Added checkable option [EuiKeyPadMenuItem] Added checkable option & style updates Jul 13, 2021
@chandlerprall chandlerprall self-requested a review July 13, 2021 21:35
Comment on lines 269 to 270
// @ts-ignore HELP!
<Element
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chandlerprall Since you self-assigned... 😉

I get this error when I remove this ignore:

Type '{ children: Element; ref: ((instance: HTMLAnchorElement | null) => void) | RefObject<HTMLAnchorElement> | ((instance: HTMLButtonElement | null) => void) | RefObject<...> | null | undefined; ... 252 more ...; onTransitionEndCapture?: ((event: TransitionEvent<...>) => void) | undefined; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'children' does not exist on type 'IntrinsicAttributes'.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've pushed a change to help address this. There's still a fallback to as Ref<any> but I don't think it's worth trying to completely satisfy TS there.

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 don't think your change got pushed

Comment on lines -16 to -21
.euiKeyPadMenuItem {
@include euiFont; /* 1 */
// Disable indentation for transition legibility
// sass-lint:disable-block indentation
display: block;
padding: $euiSizeXS;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: I moved all these item styles to their own file.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

@cchaos cchaos requested a review from elizabetdev July 13, 2021 22:30
@cchaos cchaos marked this pull request as ready for review July 13, 2021 22:30
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

/**
* Renders the the group as a `fieldset` with a `legend` to label the items.
*/
legend?: ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on moving checkable up to here and making legend required if checkable='multi'?

  1. I think it would seem weird if some of the items in a single menu are radio inputs and others checkable
  2. A radiogroup should always have a legend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I tried that but it doesn't work very well the way we make users manually supply each item vs passing in an object. Mainly the problem lies in the complexity of TS and knowing if the iterative child IS an EuiKeyPadMenuItem or not and can then accept the checkable prop as a pass-through.

Not to say it's not possible, just beyond what I can do for now. You are more than happy to take a stab at it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I'll get to it right now but will keep this in the queue.

Another option that would be easier is to require checkable in both places. It doesn't have to do much right now (even just to help with the legend bit right now seems good enough) but will also prevent a breaking change in the future when/if we get to the point that we can remove it from each item within.

It's a little duplicative but helps the upgrade path in the future of where we might want this to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, could use CSS to "block" passing in children with the wrong checkable type if we wanted to. Something like adding an obnoxious red border around mismatched items if they don't match the container.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I actually tested what happens is a legend is provided but the items aren't checkable, just <button>s and the SR does provide the legend as a grouping title which I thought was a plus outside of requiring it only if the items are checkable.

return (
return legend ? (
<fieldset className={classes} {...rest}>
<EuiFormLabel type="legend">{legend}</EuiFormLabel>
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see folks avoiding adding a legend because they don't like how it's visually presented.

Should we add the ability to visibly hide the <legend> and/or to supply an aria-label/aria-labelledby to the <fieldset> instead to give that visual flexibility or do we want to enforce a consistent style here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What approach would you like to see for that? I'd like to stay away from just a boolean isLegendVisible type of prop if possible because it can be misunderstood.

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 It's hard/low-value if checkable isn't on the KeyPadMeny (because we shouldn't force a legend if it's not checkable=multi)...

But if it is, I don't have a specific approach in mind. The isLegendVisisble flag is probably what I would have reached for first. Why don't you like it?

Another option is to have two props: legend and ariaLegend (where ariaLegend could also be called screenReaderLegend, visuallyHiddenLegend, etc)


The Charts team has basically taken the aria-* prefix to mean anything screen reader only...

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 like that approach of using ariaProp names to indicate visibility. I worry that it could confuse consumers that it is a real aria- attribute, but probably not a big deal. We can comment as such.

I don't "like" isLegendVisible, because boolean props tend not to be scalable. It's fine for very true booleans like isDisabled, but we don't know in the future what other legend options may be provided. I'll think on a solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I updated this to where EuiKeyPadMenu now accepts a singular checkable prop which can be either:

  • true: Just renders the <fieldset> and requires consumers to still pass in their own labelling via any method they like
  • { legend | ariaLegend }: Where ariaLegend is just a string applied to arial-label of the fieldset

They can further customize the <legend> with legendProps

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM, pulled & tested functionality & TypeScript configuration locally; pushed a TS change; have one small recommendation for documenting isSelected

Comment on lines 269 to 270
// @ts-ignore HELP!
<Element
Copy link
Contributor

Choose a reason for hiding this comment

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

I've pushed a change to help address this. There's still a fallback to as Ref<any> but I don't think it's worth trying to completely satisfy TS there.

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

Tested in Chrome, Safari, Edge, and Firefox. I also looked at the code. 👍🏽

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

@cchaos cchaos requested a review from myasonik July 16, 2021 19:59
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

Copy link
Contributor

@myasonik myasonik left a comment

Choose a reason for hiding this comment

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

Thanks for the changes - looks good!

I'm taking a look at the typescript issue right now, hopefully I can clobber something together.

type EuiKeyPadMenuItemPropsForAnchor = PropsForAnchor<
EuiKeyPadMenuItemCommonProps,
{
buttonRef?: Ref<HTMLAnchorElement>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on changing this (throughout the file) to itemRef? buttonRef seems confusing when it can also be an anchor...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it's a necessary breaking change?

@myasonik
Copy link
Contributor

@thompsongl Maybe you can take a pass at fixing the TS issue? I'm not getting anywhere 😕

Otherwise we can wait till Chandler's back

@cchaos
Copy link
Contributor Author

cchaos commented Jul 19, 2021

Otherwise we can wait till Chandler's back

Yes, there is no rush on this PR at all.

@thompsongl
Copy link
Contributor

thompsongl commented Jul 19, 2021

There's still a fallback to as Ref<any> but I don't think it's worth trying to completely satisfy TS there.

I arrived at what I assume is pretty much the same place as Chandler. Changes pushed.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4950/

@cchaos
Copy link
Contributor Author

cchaos commented Jul 20, 2021

Thanks all for the help and reviews!

@cchaos cchaos merged commit 30ca57f into elastic:master Jul 20, 2021
@cchaos cchaos deleted the new/checkable_keypad branch July 20, 2021 14:11
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.

[EuiKeyPadMenu] Add selection state

6 participants