Skip to content

Commit e56cc1d

Browse files
authored
fix(focus): Don't attempt to focus elements with no size
1 parent d89c79c commit e56cc1d

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

.changeset/tough-seas-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plextv/react-lightning": patch
3+
---
4+
5+
fix(focus): Don't attempt to focus elements with no size

packages/react-lightning/src/utils/findClosestElement.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,39 @@ export function findClosestElement(
195195
const sourceDimensions = getDimensions(sourceElement, parentElement);
196196

197197
for (const otherElement of elementsToCheck) {
198-
if (otherElement.focusable && otherElement !== sourceElement) {
199-
const otherDimensions = getDimensions(otherElement, parentElement);
200-
const { x: isOverlappedX, y: isOverlappedY } = isOverlap(
201-
sourceDimensions,
202-
otherDimensions,
203-
);
204-
205-
const distance = calculateShortestDistance(
206-
direction,
207-
sourceDimensions,
208-
otherDimensions,
209-
);
210-
211-
if (distance === null) {
212-
continue;
213-
}
198+
if (
199+
otherElement === sourceElement ||
200+
otherElement.node.w === 0 ||
201+
otherElement.node.h === 0 ||
202+
!otherElement.focusable
203+
) {
204+
continue;
205+
}
214206

215-
const isHorizontal = direction & Direction.Horizontal;
216-
const isOverlapped = isHorizontal ? isOverlappedY : isOverlappedX;
207+
const otherDimensions = getDimensions(otherElement, parentElement);
208+
const { x: isOverlappedX, y: isOverlappedY } = isOverlap(
209+
sourceDimensions,
210+
otherDimensions,
211+
);
217212

218-
if (distance < closestDistance && isOverlapped) {
219-
closest = [otherElement];
220-
closestDistance = distance;
221-
} else if (distance === closestDistance) {
222-
closest?.push(otherElement);
223-
}
213+
const distance = calculateShortestDistance(
214+
direction,
215+
sourceDimensions,
216+
otherDimensions,
217+
);
218+
219+
if (distance === null) {
220+
continue;
221+
}
222+
223+
const isHorizontal = direction & Direction.Horizontal;
224+
const isOverlapped = isHorizontal ? isOverlappedY : isOverlappedX;
225+
226+
if (distance < closestDistance && isOverlapped) {
227+
closest = [otherElement];
228+
closestDistance = distance;
229+
} else if (distance === closestDistance) {
230+
closest?.push(otherElement);
224231
}
225232
}
226233

packages/vite-plugin-msdf-fontgen/tsdown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default defineConfig({
55
...baseConfig,
66
format: 'esm',
77
target: 'node22',
8+
external: [/^node:.*/],
89
exports: {
910
devExports: false,
1011
},

packages/vite-plugin-react-reanimated-lightning/tsdown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default defineConfig({
55
...baseConfig,
66
format: 'esm',
77
target: 'node22',
8+
external: [/^node:.*/],
89
exports: {
910
devExports: false,
1011
},

0 commit comments

Comments
 (0)