Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions packages/@react-spectrum/datepicker/src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,32 @@ function Input(props, ref) {
// not cause a layout shift.
let [reservePadding, setReservePadding] = useValueEffect(false);
let onResize = useCallback(() => setReservePadding(function *(reservePadding) {
if (reservePadding) {
// Try to collapse padding if the content is clipped.
if (inputRef.current.scrollWidth > inputRef.current.offsetWidth) {
let width = inputRef.current.parentElement.offsetWidth;
yield false;
if (inputRef.current) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The diff is weird, this is just wrapping the old if statement in a inputRef.current check

Copy link
Member Author

Choose a reason for hiding this comment

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

The diff is weird, this is just wrapping the old if statement in a inputRef.current check

if (reservePadding) {
// Try to collapse padding if the content is clipped.
if (inputRef.current.scrollWidth > inputRef.current.offsetWidth) {
let width = inputRef.current.parentElement.offsetWidth;
yield false;

// If removing padding causes a layout shift, add it back.
if (inputRef.current.parentElement.offsetWidth !== width) {
yield true;
// If removing padding causes a layout shift, add it back.
if (inputRef.current.parentElement.offsetWidth !== width) {
yield true;
}
}
}
} else {
// Try to add padding if the content is not clipped.
if (inputRef.current.offsetWidth >= inputRef.current.scrollWidth) {
let width = inputRef.current.parentElement.offsetWidth;
yield true;
} else {
// Try to add padding if the content is not clipped.
if (inputRef.current.offsetWidth >= inputRef.current.scrollWidth) {
let width = inputRef.current.parentElement.offsetWidth;
yield true;

// If adding padding does not change the width (i.e. width is constrained), remove it again.
if (inputRef.current.parentElement.offsetWidth === width) {
yield false;
// If adding padding does not change the width (i.e. width is constrained), remove it again.
if (inputRef.current.parentElement.offsetWidth === width) {
yield false;
}
}
}
}

}), [inputRef, setReservePadding]);

useLayoutEffect(onResize, [onResize]);
Expand Down