Skip to content

Commit 8a9628d

Browse files
DamienGarnesgcornut
authored andcommitted
fix(thumbnail): handle 0 in focalPoint properly
1 parent 5ed497a commit 8a9628d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `Thumbnail`: fix focal points equal to 0
13+
1014
### Changed
1115

1216
- `Button`: add disabled behavior with `aria-disabled` only
@@ -59,7 +63,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5963
- `Link`: deprecated `rightIcon`/`leftIcon` props (use nested icons instead)
6064
- `Link` docs: rework documentation page
6165

62-
6366
## [3.12.0][] - 2025-03-19
6467

6568
### Added
@@ -133,8 +136,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
133136
- `Chip`: add border and background color CSS variable theming on selected state.
134137
- `SideNavigationItem`: add border CSS variable theming on selected state.
135138
- `Button`: deprecated variables `--lumx-button-emphasis-selected-state-default-padding-horizontal`,
136-
`--lumx-button-emphasis-selected-hover-hover-padding-horizontal` and
137-
`--lumx-button-emphasis-selected-hover-active-padding-horizontal` (use the base `low` or `medium` emphasis padding)
139+
`--lumx-button-emphasis-selected-hover-hover-padding-horizontal` and
140+
`--lumx-button-emphasis-selected-hover-active-padding-horizontal` (use the base `low` or `medium` emphasis padding)
138141

139142
### Fixed
140143

@@ -148,9 +151,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
148151
- Storybook `withCombinations()`: better section heading, exclude combinations
149152
- Storybook `withTheming()`: new decorator to demonstrate CSS variables on stories
150153
- Storybook `Button`:
151-
- Cleaned up stories argTypes and controls
152-
- Rework stories content with more combinations
153-
- Add theming story
154+
- Cleaned up stories argTypes and controls
155+
- Rework stories content with more combinations
156+
- Add theming story
154157
- Storybook `DatePicker`: add theming story
155158
- Storybook `Chip`: add theming story
156159
- Storybook `Navigation`: add variants & theming stories

packages/lumx-react/src/components/thumbnail/useFocusPointStyle.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,18 @@ export const useFocusPointStyle = (
6262
);
6363

6464
// Compute style.
65-
const [style, setStyle] = useState<CSSProperties>({});
66-
useEffect(() => {
65+
const style: CSSProperties = useMemo(() => {
6766
// Focus point is not applicable => exit early
6867
if (!image || aspectRatio === AspectRatio.original || (!focusPoint?.x && !focusPoint?.y)) {
69-
return;
68+
return {};
7069
}
7170
if (!element || !imageSize) {
7271
// Focus point can be computed but now right now (image size unknown).
73-
setStyle({ visibility: 'hidden' });
74-
return;
72+
return { visibility: 'hidden' };
7573
}
7674
if (!containerSize || !imageSize.height || !imageSize.width) {
7775
// Missing container or image size abort focus point compute.
78-
setStyle({});
79-
return;
76+
return {};
8077
}
8178

8279
const heightScale = imageSize.height / containerSize.height;
@@ -102,8 +99,8 @@ export const useFocusPointStyle = (
10299
});
103100

104101
const objectPosition = `${x}% ${y}%`;
105-
// Update only if needed.
106-
setStyle((oldStyle) => (oldStyle.objectPosition === objectPosition ? oldStyle : { objectPosition }));
102+
103+
return { objectPosition };
107104
}, [aspectRatio, containerSize, element, focusPoint?.x, focusPoint?.y, image, imageSize]);
108105

109106
return style;

0 commit comments

Comments
 (0)