Skip to content

Commit

Permalink
Merge pull request #2099 from VKCOM/bug/2098-focustrap-nodelist
Browse files Browse the repository at this point in the history
  • Loading branch information
eugpoloz authored Nov 19, 2021
2 parents a08219a + 9f3212f commit 6b51b5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/components/CardScroll/CardScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const CardScroll: React.FC<CardScrollProps> = ({ children, size, sizeX, ...restP

function getScrollToRight(offset: number): number {
const containerWidth = refContainer.current.offsetWidth;
const slide = Array.from(refContainer.current.children).find((el: HTMLElement) => el.offsetLeft + el.offsetWidth - offset > containerWidth) as HTMLElement;
const slide = Array.prototype.find.call(
refContainer.current.children,
(el: HTMLElement) => el.offsetLeft + el.offsetWidth - offset > containerWidth,
) as HTMLElement;

if (!slide) {
return offset;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Cell/useDraggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useDraggable = ({ onDragFinish }: Pick<CellProps, 'onDragFinish'>)

setDragging(true);

const _siblings: HTMLElement[] = Array.from(rootEl.parentElement.childNodes);
const _siblings: HTMLElement[] = [...rootEl.parentElement.childNodes];
const idx = _siblings.indexOf(rootEl);

setDragStartIndex(idx);
Expand Down
19 changes: 11 additions & 8 deletions src/components/FocusTrap/FocusTrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ export const FocusTrap: React.FC<FocusTrapProps> = ({
}

const nodes: HTMLElement[] = [];
// eslint-disable-next-line no-restricted-properties
ref.current?.querySelectorAll(FOCUSABLE_ELEMENTS).forEach((focusableEl) => {
const { display, visibility } = window.getComputedStyle(focusableEl);

if (display !== 'none' && visibility !== 'hidden') {
nodes.push(focusableEl as HTMLElement);
}
});
Array.prototype.forEach.call(
// eslint-disable-next-line no-restricted-properties
ref.current.querySelectorAll(FOCUSABLE_ELEMENTS),
(focusableEl: Element) => {
const { display, visibility } = window.getComputedStyle(focusableEl);

if (display !== 'none' && visibility !== 'hidden') {
nodes.push(focusableEl as HTMLElement);
}
},
);

if (nodes?.length) {
setFocusableNodes(nodes);
Expand Down

0 comments on commit 6b51b5f

Please sign in to comment.