Skip to content

Commit 00093f8

Browse files
author
Formaleva Maria
committed
add prop noPadding
1 parent 3dfe9d7 commit 00093f8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/vkui/src/components/SubnavigationBar/SubnavigationBar.module.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.in {
22
/* Отрицательный margin нужен, чтобы компенсировать увеличенный из-за тени padding (12px -> 20px) */
33
position: relative;
4-
/* min-width: 100%; */
54
margin-block: -8px;
65
margin-inline: 0;
76
overflow-x: hidden;
@@ -32,6 +31,10 @@
3231
display: none;
3332
}
3433

34+
.noPadding {
35+
padding: 0;
36+
}
37+
3538
.item {
3639
display: flex;
3740
list-style-type: none;

packages/vkui/src/components/SubnavigationBar/SubnavigationBar.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface SubnavigationBarProps
2626
* Добавляет тень слева и справа при скролле.
2727
*/
2828
withFade?: boolean;
29+
/**
30+
* Убрать отступы.
31+
*/
32+
noPadding?: boolean;
2933
}
3034

3135
const defaultScrollToLeft: ScrollPositionHandler = (x) => x - 240;
@@ -40,6 +44,7 @@ export const SubnavigationBar = ({
4044
withFade = false,
4145
children,
4246
showArrows = true,
47+
noPadding = false,
4348
getScrollToLeft = defaultScrollToLeft,
4449
getScrollToRight = defaultScrollToRight,
4550
scrollAnimationDuration,
@@ -61,8 +66,8 @@ export const SubnavigationBar = ({
6166
}
6267

6368
const scrollRef = useRef<HTMLDivElement>(null);
64-
const [ isFadeLeft, setFadeLeft ] = useState(false);
65-
const [ isFadeRight, setFadeRight ] = useState(false);
69+
const [isFadeLeft, setFadeLeft] = useState(false);
70+
const [isFadeRight, setFadeRight] = useState(false);
6671

6772
const scrollHandler = useCallback(() => {
6873
if (!scrollRef.current) {
@@ -71,13 +76,16 @@ export const SubnavigationBar = ({
7176

7277
setFadeLeft(scrollRef.current.scrollLeft !== 0);
7378
setFadeRight(
74-
!(scrollRef.current.clientWidth + scrollRef.current.scrollLeft >= scrollRef.current.scrollWidth)
79+
!(
80+
scrollRef.current.clientWidth + scrollRef.current.scrollLeft >=
81+
scrollRef.current.scrollWidth
82+
),
7583
);
7684
}, []);
7785

7886
const renderScrollWrapper = () => (
7987
<ScrollWrapper className={styles.in} {...scrollWrapperProps}>
80-
<ul className={styles.scrollIn}>
88+
<ul className={classNames(styles.scrollIn, noPadding && styles.noPadding)}>
8189
{React.Children.map(children, (child, idx) =>
8290
hasReactNode(child) ? (
8391
<li key={idx} className={styles.item}>

0 commit comments

Comments
 (0)