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

[Tabs] Update position when layout change (ResizeObserver) #9337

Closed
1 task done
samdenty opened this issue Nov 29, 2017 · 29 comments · Fixed by #27791
Closed
1 task done

[Tabs] Update position when layout change (ResizeObserver) #9337

samdenty opened this issue Nov 29, 2017 · 29 comments · Fixed by #27791
Labels
component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@samdenty
Copy link
Contributor

samdenty commented Nov 29, 2017

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Tab indicator should dynamically resize its width when the parent container width changes

Current Behavior

Tab indicator doesn't resize when the parent container width changes ~ only when the viewport size does

When parent container size changes:
image
What it should look like / what it looks like after triggering a re-render:
image

Steps to Reproduce (for bugs)

  1. Create a container with a child tab element in it (fullwidth)
  2. Resize the parent container programmatically (not by changing the viewport)

Context

I'm using the tabs in a appbar using the persistent drawer layout, opening / closing the menu breaks the tab indicators until a manual re-render

Your Environment

Tech Version
Material-UI 1.0.0-beta.20
React 15.5.4
browser Chrome 63.0.3239.59
@samdenty samdenty changed the title Tab indicator positions break upon parent container resize Tab indicator positions breaks upon parent container resize Nov 29, 2017
@mbrookes

This comment has been minimized.

@mbrookes mbrookes added component: tabs This is the name of the generic UI component, not the React module! waiting for user information labels Dec 2, 2017
@mbrookes

This comment has been minimized.

@oliviertassinari oliviertassinari added new feature New feature or request and removed waiting for user information labels Dec 7, 2017
@oliviertassinari

This comment has been minimized.

@oliviertassinari oliviertassinari changed the title Tab indicator positions breaks upon parent container resize [Tabs] Update indicator positions upon parent container resize Dec 7, 2017
@gregnb

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@gregnb

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@gregnb

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@gregnb

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@gregnb

This comment has been minimized.

@01e9

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@KyleAsaff

This comment has been minimized.

@samdenty
Copy link
Contributor Author

samdenty commented Feb 25, 2018

I ended up just triggering a window resize event

window.dispatchEvent(new CustomEvent('resize'))

@01e9

This comment has been minimized.

@gadkadosh

This comment has been minimized.

@samdenty

This comment has been minimized.

@gadkadosh

This comment has been minimized.

@oliviertassinari oliviertassinari added the waiting for 👍 Waiting for upvotes label Sep 23, 2019
@oliviertassinari oliviertassinari removed the waiting for 👍 Waiting for upvotes label Nov 30, 2019
@oliviertassinari oliviertassinari changed the title [Tabs] Update indicator position upon parent resize [Tabs] Update position when layout change (ResizeObserver) Dec 1, 2019
@robertsoniv
Copy link

We observe this same issue when using fontDisplay: swap with our custom fonts. Since our custom font is not as wide as browser default, the indicator is always off on first page load.

@AncientSwordRage
Copy link

I observe the same issue when we have the tabs in a popover, but the fix below does not work for us

We have added an action prop to the Tabs component since to solve the problem. You can trigger the .updateIndicator() method when you need to update the position of the indicator.

For instance:

function MyTabs() {
  const tabsActions = React.useRef();

  React.useEffect(() => {
    if (tabsActions.current) {
      tabsActions.current.updatePosition();
    }
  }, [x]);

  return <Tabs action={tabsActions}>{items}</Popover>;
}

@craigpullar
Copy link

We find the same issue with the Modal and the ref/resize fix does not work for us either

@AncientSwordRage
Copy link

We find the same issue with the Modal and the ref/resize fix does not work for us either

See my fix here #19786 (comment)

@luan-dang-techlabs
Copy link

I observe the same issue when we have the tabs in a popover, but the fix below does not work for us

We have added an action prop to the Tabs component since to solve the problem. You can trigger the .updateIndicator() method when you need to update the position of the indicator.
For instance:

function MyTabs() {
  const tabsActions = React.useRef();

  React.useEffect(() => {
    if (tabsActions.current) {
      tabsActions.current.updatePosition();
    }
  }, [x]);

  return <Tabs action={tabsActions}>{items}</Popover>;
}

This worked well for me 👍 thanks for the help.

const containerRef = useRef(null);
const actionRef = useRef<TabsActions | null>(null);

useEffect(() => {
    const ro = new ResizeObserver(() => {
      if (actionRef.current && containerRef.current) {
        actionRef.current.updateIndicator();
      }
    });

    if (containerRef.current) {
      ro.observe(containerRef.current);
    }
  }, [containerRef.current, actionRef.current]);



<Container ref={containerRef}>

            <TabList
              action={actionRef}
              value={searchTab}
              onChange={handleSearchTabChange}
              indicatorColor="primary"
              centered
            >
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.