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

fix(Breadcrumb): icon direction on mobile when variant collapse #4452

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -14,7 +14,7 @@ import P from '../../elements/P'
import homeIcon from '../../icons/home'

// Shared
import { useMediaQuery } from '../../shared'
import { useMediaQuery, useTheme } from '../../shared'
import Context from '../../shared/Context'
import type { SkeletonShow } from '../skeleton/Skeleton'
import {
Expand Down Expand Up @@ -77,19 +77,24 @@ const defaultProps = {
skeleton: null,
}

const determineIcon = (variant: string, isSmallScreen: boolean) => {
const determineIcon = (
variant: string,
isSmallScreen: boolean,
isSbanken: boolean
) => {
switch (variant) {
case 'home':
return 'home-icon'
case 'single':
case 'collapse':
return 'chevron_left'
default:
return isSmallScreen ? 'chevron_left' : 'chevron_right'
return isSbanken && isSmallScreen ? 'chevron_left' : 'chevron_right'
}
}

const BreadcrumbItem = (localProps: BreadcrumbItemProps) => {
const isSbanken = useTheme()?.isSbanken
// Every component should have a context
const context = React.useContext(Context)
const {
Expand Down Expand Up @@ -125,7 +130,7 @@ const BreadcrumbItem = (localProps: BreadcrumbItemProps) => {

useLayoutEffect(() => {
if (!icon) {
setCurrentIcon(determineIcon(variant, isSmallScreen))
setCurrentIcon(determineIcon(variant, isSmallScreen, isSbanken))
} else {
if (variant !== 'home') {
setCurrentIcon(icon ?? 'chevron_left')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,17 @@ describe.each(['ui', 'sbanken'])('Breadcrumb for %s', (themeName) => {
})
expect(screenshot).toMatchImageSnapshot()
})

it('have to match Breadcrumb collapse opened', async () => {
const screenshot = await makeScreenshot({
selector:
'[data-visual-test="breadcrumb-collapse"] .dnb-breadcrumb',
simulateSelector:
'[data-visual-test="breadcrumb-collapse"] .dnb-breadcrumb__toggle',
recalculateHeightAfterSimulate: true,
simulate: 'click',
})
expect(screenshot).toMatchImageSnapshot()
})
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading