Skip to content

[EuiTabs] Child EuiTabs in nested wrappers do not correctly inherit size from EuiTabs #6367

Closed

Description

@cee-chen

As of the EuiTabs Emotion conversion (#6311), child EuiTab now need to be passed size and expand.

const tabItems = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return cloneElementWithCss(child, {
// we're passing the parent `size` and `expand` down to the children
size: size,
expand: expand,
});
}
});

However, the above code only captures EuiTab children that are direct descendants of EuiTabs. It does not correctly pass down size to grandchild, anywhere within the EuiTabs parent, e.g.

<EuiTabs size="l">
  <SomeIntermediateWrapper>
    <EuiTab> // will be size "m" / will not inherit size "l"

Link to actual production example in Kibana where consumers have a perfectly acceptable use case of a React component wrapper that handles click behavior.

The more robust architecture/approach we should be using is using a React context provider to pass size and expand to all children, following EuiDescriptionList's example:

<EuiDescriptionListContext.Provider
value={{ type, compressed, textStyle, align, gutterSize }}
>

Activity

  1. cee-chen commented on Nov 15, 2022

    @cee-chen
    ContributorAuthor

    @breehall would you be interested in picking this up some point, since you already have props/context experience from EuiDescriptionList? 🙏

  2. changed the title [-][EuiTabs] Child `EuiTab` in nested wrappers do not correctly inherit `size` from `EuiTabs`[/-] [+][EuiTabs] Child `EuiTab`s in nested wrappers do not correctly inherit `size` from `EuiTabs`[/+] on Nov 15, 2022
  3. dawitamene commented on Dec 2, 2022

    @dawitamene
    Contributor

    @constancecchen, If maybe @breehall is busy, can I work on this?

  4. cee-chen commented on Dec 2, 2022

    @cee-chen
    ContributorAuthor

    @dawitam11 Absolutely!

  5. dawitamene commented on Dec 8, 2022

    @dawitamene
    Contributor

    @constancecchen

    For backward compatibility and to be able to customize individual tabs separately, EuiTab component would have size and expand both from its own props and from EuiTabsContext right?

    export const EuiTab: FunctionComponent = ({
      isSelected,
      children,
      className,
      disabled: _disabled,
      href,
      target,
      rel,
      prepend,
      append,
      size, 
      expand,
      ...rest
    }) => {
      const { size: parentSize, expand: parentExpand } = useContext(EuiTabsContext) 
      const euiTheme = useEuiTheme();
      const isHrefValid = !href || validateHref(href);
      const disabled = _disabled || !isHrefValid;
    
    
    

    And use values from context only if size or expand props of EuiTab are undefined (not passed by user ), then add styles from Emotion like (expand ?? parentExpand) && tabStyles.expanded,. In other words, prop values will take precedence over context values.

  6. cee-chen commented on Dec 8, 2022

    @cee-chen
    ContributorAuthor

    Hmmm - so, on principle I agree with you, but for consistency I think we'd want to handle this the same way we handle children in EuiDescriptionList. It looks like we do not inherit props directly, and instead now fully rely on context:

    export const EuiDescriptionListTitle: FunctionComponent<EuiDescriptionListTitleProps> = ({
    children,
    className,
    ...rest
    }) => {
    const { type, textStyle, compressed, align, gutterSize } = useContext(
    EuiDescriptionListContext
    );

    I think this is valid honestly because no one should really be using EuiTab outside of EuiTabs (and mostly people use EuiTabs with the tabs API in any case as opposed to individual children).

    My vote would be to mark the removal of size and expand on EuiTab as a breaking change, and inherit only from the context. TBH, for those specific props it makes sense as well from a design/UI perspective - we don't really want consumers creating tab groups of varying sizes and expansion levels.

    Hope that makes sense!

  7. dawitamene commented on Dec 13, 2022

    @dawitamene
    Contributor

    @constancecchen

    I thought that way in order to not break any existing functionality by doing so. If we are going to mark it as breaking change, I agree with everything you said. Thanks for your detailed explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions