replace custom useAutoSize hook with native field-sizing: content#716
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
replace custom
useAutoSizehook with nativefield-sizing: contentwhat changed
removed
useAutoSizehookdeleted the custom
useAutoSizehook that used a hidden mirror<span>to measure text width and manually set input/textarea widths. it also created container refs that had to be threaded through to every rename input.added
field-sizing-contentandwidth-fit-contentutilitiesadded two new utilities in
globals.css:.field-sizing-contentsetsfield-sizing: contentso inputs and textareas naturally shrink/grow to fit their content (native browser behavior).width-fit-contentsetswidth: fit-contentas a companion for elements that need itupdated all rename inputs
every inline rename input that used
useAutoSizenow usesfield-sizing-content width-fit-content min-w-fit max-w-full(ormax-w-[220px]for tab names) instead:WorkingSpacePageClientHomePageClientremoved container refs
all the
nameContainerRef,tabContainerRef,gridContainerRef,listContainerRefrefs that existed solely to pass max-width bounds touseAutoSizeare gone. also removeduseLayoutEffectimport since it was only used by the hook.misc
pr-8removed from workspace card title hover border (wasn't needed)mt-0.5for alignmentw-full sm:w-autoon the filter controls changed tow-autohover:px-2removed from list note titlewhy
field-sizing: contentis now well-supported and does exactly what the custom hook did, with zero js. the old approach was fragile (sync issues, extra dom elements) and added complexity to every component that needed auto-sizing.