File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @walrusk/react-responsive-div" ,
3- "version" : " 1.0.0 " ,
3+ "version" : " 1.0.1 " ,
44 "description" : " Responsive React container using breakpoints based on container (not viewport) width." ,
55 "homepage" : " https://github.com/walrusk/react-responsive-div#readme" ,
66 "author" : " Rob Norman <walrusk@gmail.com> (https://magnetnet.net)" ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export function useResizeObserver(breakpointObj, containerRef) {
2929 return breakpoints . find ( ( bp , i ) => {
3030 const min = breakpointObj [ bp ] ;
3131 const max = breakpointObj [ breakpoints [ i + 1 ] ] ;
32- if ( width >= min && ( ! max || width < max ) ) {
32+ if ( ( i === 0 || width >= min ) && ( ! max || width < max ) ) {
3333 return true ;
3434 }
3535 } ) ;
@@ -38,12 +38,11 @@ export function useResizeObserver(breakpointObj, containerRef) {
3838 if ( window . ResizeObserver ) {
3939 const ro = new window . ResizeObserver ( ( entries ) => {
4040 entries . forEach ( ( entry ) => {
41- // Update breakpoints
4241 const breakpoint = getBreakpoint ( entry . contentRect . width ) ;
43- if ( ! entry . target . classList . contains ( breakpoint ) ) {
42+ if ( breakpoint && ! entry . target . classList . contains ( breakpoint ) ) {
4443 entry . target . classList . remove ( ...breakpoints ) ;
4544 entry . target . classList . add ( breakpoint ) ;
46- } // else it already contains the class we want :+1:
45+ }
4746 } ) ;
4847 } ) ;
4948 ro . observe ( containerRef . current ) ;
You can’t perform that action at this time.
0 commit comments