Add ResizeObserver abstraction
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, react
- Domain
- frontend
Research direction
Start by reviewing the proposed useResizeObserver API and the related issues #9337, #22303, #23641, and #27439. Compare the existing DataGrid createDetectElementResize module and the listed browser-support constraints. Done means the abstraction's scope, progressive-enhancement behavior, compatibility expectations, and documentation are defined and covered by appropriate tests.
Written by the indexing model from the issue text.
Description
- I have searched the issues of this repository and believe that this is not a duplicate.
Summary 💡
Make it easier to react to changes from an element's position.
Examples 🌈
import { useResizeObserver } from '@material-ui/core';
const [rect, ref] = useResizeObserver();
return (
<div ref={ref}>
{JSON.stringify(rect)}
</div>
);
Motivation 🔦
The platform has a built-in module to observe any changes to element.getBoundingClientRect(): the ResizeObserver API.
Over the history of the project, we have seen a couple of issues that we can solve with it:
- #9337: correctly position the tab indicator. The interesting part of this issue is how many duplicate issues it has: A LOT. There is also a relatively simple workaround (but requires time and attention from the developers): a ref with an imperative update() method to reposition.
- #22303: notify popper.js to update the position when the size of the referred element changes.
- https://github.com/mui-org/material-ui/pull/14084#issuecomment-462192106: we could use it to implement auto collapsing breadcrumbs.
- #23641: sync the height of the textarea when the width changes.
- DataGrid: replace the
createDetectElementResize()module. - #27439 : already uses the ResizeObserver API to re-compute the height of the content of
MasonryItemwhenever the content's rect height changes.
So far, we didn't move forward in this direction because of the limited support of the platform. However, the timing is probably good now: https://twitter.com/addyosmani/status/1248899086490558465. For our components, we could make the hook nop if the API isn't available (consider it a progressive enhancement) and in the documentation of the hook suggest a polyfill like https://github.com/que-etc/resize-observer-polyfill compatibility with older browsers is required.
Browser support
We support browsers that aren't supported by this API. We could provide this as a progressive enhancement.
In the data grid, we use createDetectElementResize to work around the issue but it requires a DOM node, it can be a "heavy" solution. I think that it's simpler to go down the "progressive enhancement" direction.
Benchmark
- https://blueprintjs.com/docs/#core/components/resize-sensor
- https://github.com/souporserious/react-measure
- https://react-restart.github.io/hooks/api/useResizeObserver
- https://reach.tech/rect/
- https://elastic.github.io/eui/#/utilities/resize-observer
- https://github.com/wellyshen/react-cool-dimensions
- https://github.com/envato/react-breakpoints
- https://github.com/ctrlplusb/react-sizeme
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mui/material-ui
-
type: new feature waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#48254 · 3 comments · 1 reaction ·
-
has workaround scope: avatar waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mui/material-ui#48190 · 5 comments ·
-
has workaround scope: typography type: new feature waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
mui/material-ui#46488 · 2 comments · 1 reaction ·
-
has workaround scope: text field type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#37216 · 6 comments ·
-
docs scope: autocomplete
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#35713 · 5 comments ·
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100