Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide horizontal overflow in Navigator #35332

Merged
merged 8 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';
import { css } from '@emotion/react';

/**
* WordPress dependencies
Expand All @@ -17,6 +18,7 @@ import {
useContextSystem,
WordPressComponentProps,
} from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import { View } from '../../view';
import { NavigatorContext } from '../context';
import type { NavigatorProviderProps, NavigatorPath } from '../types';
Expand All @@ -25,17 +27,21 @@ function NavigatorProvider(
props: WordPressComponentProps< NavigatorProviderProps, 'div' >,
forwardedRef: Ref< any >
) {
const { initialPath, children, ...otherProps } = useContextSystem(
props,
'NavigatorProvider'
);
const {
initialPath,
children,
className,
...otherProps
} = useContextSystem( props, 'NavigatorProvider' );

const [ path, setPath ] = useState< NavigatorPath >( {
path: initialPath,
} );

const classes = useCx()( css( { overflowX: 'hidden' } ), className );
stokesman marked this conversation as resolved.
Show resolved Hide resolved

return (
<View ref={ forwardedRef } { ...otherProps }>
<View ref={ forwardedRef } className={ classes } { ...otherProps }>
<NavigatorContext.Provider value={ [ path, setPath ] }>
{ children }
</NavigatorContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { Ref } from 'react';
// eslint-disable-next-line no-restricted-imports
import { motion, MotionProps } from 'framer-motion';
import { css } from '@emotion/react';

/**
* WordPress dependencies
Expand All @@ -21,6 +22,7 @@ import {
useContextSystem,
WordPressComponentProps,
} from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import { View } from '../../view';
import { NavigatorContext } from '../context';
import type { NavigatorScreenProps } from '../types';
Expand All @@ -38,7 +40,7 @@ type Props = Omit<
>;

function NavigatorScreen( props: Props, forwardedRef: Ref< any > ) {
const { children, path, ...otherProps } = useContextSystem(
const { children, className, path, ...otherProps } = useContextSystem(
props,
'NavigatorScreen'
);
Expand All @@ -47,6 +49,7 @@ function NavigatorScreen( props: Props, forwardedRef: Ref< any > ) {
const [ currentPath ] = useContext( NavigatorContext );
const isMatch = currentPath.path === path;
const ref = useFocusOnMount();
const cx = useCx();

// This flag is used to only apply the focus on mount when the actual path changes.
// It avoids the focus to happen on the first render.
Expand Down Expand Up @@ -104,9 +107,12 @@ function NavigatorScreen( props: Props, forwardedRef: Ref< any > ) {
initial,
};

const classes = cx( css( { overflowX: 'auto' } ), className );
stokesman marked this conversation as resolved.
Show resolved Hide resolved

return (
<motion.div
ref={ hasPathChanged ? ref : undefined }
className={ classes }
{ ...otherProps }
{ ...animatedProps }
>
Expand Down