Skip to content

Commit 53e5e58

Browse files
Custom horizontal scrollbar support
1 parent db2017a commit 53e5e58

File tree

12 files changed

+117
-14
lines changed

12 files changed

+117
-14
lines changed

app/integrations/woocommerce/wc-template-functions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function woocommerce_output_product_categories( $args = [] ) {
7878
if ( $total > 5 ) {
7979
$product_categories = array_slice( $product_categories, 0, 5 );
8080
}
81+
8182
// End modification.
8283
if ( ! $product_categories ) {
8384
return false;

package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"postcss-loader": "3.0.0",
3737
"raw-loader": "3.1.0",
3838
"sass-loader": "7.2.0",
39+
"simplebar": "4.1.0",
3940
"stylelint": "10.1.0",
4041
"stylelint-config-wordpress": "14.0.0",
4142
"svg-sprite-loader": "4.1.6",

resources/assets/js/app/horizontal-menu.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Extenal dependencies.
3+
*/
4+
import SimpleBar from 'simplebar';
5+
16
/**
27
* Scroll a horizontal menu to the active item.
38
*
@@ -11,6 +16,8 @@ const horizontalMenu = ( menuClass, activeClass ) => {
1116
return;
1217
}
1318

19+
// Custom scrolling.
20+
const simpleBar = new SimpleBar( menu );
1421
const activeLink = document.querySelector( `${ menuClass } ${ activeClass }` );
1522

1623
if ( ! activeLink ) {
@@ -20,7 +27,7 @@ const horizontalMenu = ( menuClass, activeClass ) => {
2027
const activeOffset = activeLink.getBoundingClientRect();
2128
const menuOffset = menu.getBoundingClientRect();
2229

23-
menu.scrollLeft = activeOffset.x + ( activeOffset.width / 2 ) + menu.scrollLeft - ( menuOffset.width / 2 );
30+
simpleBar.getScrollElement().scrollLeft = activeOffset.x + ( activeOffset.width / 2 ) + menu.scrollLeft - ( menuOffset.width / 2 );
2431
};
2532

2633
export default horizontalMenu;

resources/assets/js/woocommerce/account-menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import domReady from '@wordpress/dom-ready';
88
*/
99
import horizontalMenu from './../app/horizontal-menu.js';
1010

11-
domReady( horizontalMenu( '.woocommerce-MyAccount-navigation ul', '.is-active' ) );
11+
domReady( horizontalMenu( '.woocommerce-MyAccount-navigation', '.is-active' ) );
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* External dependencies.
3+
*/
4+
import domReady from '@wordpress/dom-ready';
5+
6+
/**
7+
* Internal dependencies.
8+
*/
9+
import horizontalMenu from './../app/horizontal-menu.js';
10+
11+
domReady( horizontalMenu( '.woocommerce-product-categories-wrapper' ) );

resources/assets/js/woocommerce/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ import './checkout.js';
1717
import './products.js';
1818
import './lazyload.js';
1919
import './account-menu.js';
20+
import './category-menu.js';

resources/assets/scss/_config.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
@import "~bootstrap/scss/mixins/grid";
2121
@import "~bootstrap/scss/grid";
2222

23+
// SimpleBar
24+
@import "~simplebar/src/simplebar.css";
25+
2326
/**
2427
* Internal dependencies
2528
*/

resources/assets/scss/modules/products-categories.scss

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
// [1] Give any potential scrollbar more room so it does not overlap.
1+
.woocommerce-product-categories-wrapper {
2+
-webkit-overflow-scrolling: touch;
3+
margin-bottom: $spacer;
4+
}
5+
26
.woocommerce-page ul.products-categories,
37
.woocommerce ul.products-categories {
48
display: flex;
5-
overflow-x: scroll;
6-
-webkit-overflow-scrolling: touch;
79
position: relative;
8-
padding-bottom: $spacer; // [1]
10+
11+
@include reset-list();
12+
913
padding-left: 2px;
1014
padding-right: 2px;
1115

@@ -17,10 +21,7 @@
1721
border-radius: $border-radius;
1822
}
1923

20-
2124
@include gray("background", "200");
22-
bottom: $spacer;
23-
height: calc(100% - #{$spacer});
2425
}
2526

2627
@include vertical-spacing("margin", "down", (

resources/assets/scss/modules/woocommerce-account.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// [1] Give any potential scrollbar more room so it does not overlap.
21
.woocommerce-MyAccount-navigation {
32
margin: -($spacer) 0 $spacer;
3+
padding: 0 0 $spacer;
44
position: relative;
5+
-webkit-overflow-scrolling: touch;
56

67
&::after {
78
content: "";
@@ -21,11 +22,9 @@
2122

2223
@include reset-list();
2324

24-
padding: 0 0 $spacer; // [1]
25+
margin: 0;
26+
padding: 0;
2527
display: flex;
26-
overflow-x: scroll;
27-
overflow-y: hidden;
28-
-webkit-overflow-scrolling: touch;
2928

3029
li {
3130
flex: 1 0 auto;

0 commit comments

Comments
 (0)