• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

react-ui-org / react-ui / 13409901360

19 Feb 2025 09:59AM UTC coverage: 91.956%. First build
13409901360

Pull #544

github

web-flow
Merge b0b2c90f9 into 87ee7df12
Pull Request #544: Re-implement `Modal` component using HTMLDialogElement (#461)

785 of 859 branches covered (91.39%)

Branch coverage included in aggregate %.

31 of 33 new or added lines in 4 files covered. (93.94%)

724 of 782 relevant lines covered (92.58%)

72.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/src/components/Modal/_hooks/useModalScrollPrevention.js
1
import { useLayoutEffect } from 'react';
2

3
export const useModalScrollPrevention = (preventScrollUnderneath) => {
4✔
4
  useLayoutEffect(
50✔
5
    () => {
6
      if (preventScrollUnderneath === 'off') {
50✔
7
        return () => {};
2✔
8
      }
9

10
      if (preventScrollUnderneath instanceof HTMLElement) {
48✔
11
        const scrollableElement = preventScrollUnderneath;
46✔
12

13
        const scrollbarWidth = Math.abs(window.innerWidth - window.document.documentElement.clientWidth);
46✔
14
        const prevOverflow = scrollableElement.style.overflow;
46✔
15
        const prevPaddingRight = scrollableElement.style.paddingRight;
46✔
16

17
        scrollableElement.style.overflow = 'hidden';
46✔
18

19
        if (Number.isNaN(parseInt(prevPaddingRight, 10))) {
46!
20
          scrollableElement.style.paddingRight = `${scrollbarWidth}px`;
46✔
21
        } else {
22
          scrollableElement.style.paddingRight = `calc(${prevPaddingRight} + ${scrollbarWidth}px)`;
×
23
        }
24

25
        return () => {
46✔
26
          scrollableElement.style.overflow = prevOverflow;
46✔
27
          scrollableElement.style.paddingRight = prevPaddingRight;
46✔
28
        };
29
      }
30

31
      preventScrollUnderneath?.start();
2✔
32

33
      return preventScrollUnderneath?.reset;
2✔
34
    },
35
    [preventScrollUnderneath],
36
  );
37
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc