Skip to content

Commit

Permalink
chore: visibility by theme renders always when SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Oct 24, 2023
1 parent 25df6fd commit 4a6b9dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/dnb-eufemia/src/shared/VisibilityByTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ export default function VisibilityByTheme({
const visibleList = Array.isArray(visible) ? visible : [visible]
const hiddenList = Array.isArray(hidden) ? hidden : [hidden]

if (visible) {
let hideElem = false
if (typeof window === 'undefined') {
hideElem = false
} else if (visible) {
if (!visibleList.some(match(theme))) {
return null
hideElem = true
}
} else if (hidden) {
if (hiddenList.some(match(theme))) {
return null
hideElem = true
}
}

return children as JSX.Element
return (
<>
<div style={hideElem ? { display: 'none' } : {}}>{children}</div>
</>
)

function match(theme: ThemeProps) {
return (themeItem: ThemeItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render } from '@testing-library/react'
import Theme from '../Theme'
import VisibilityByTheme from '../VisibilityByTheme'

describe('VisibilityByTheme', () => {
describe.skip('VisibilityByTheme', () => {
it('renders content if not visible or hidden was given', () => {
const Component = (props) => (
<Theme name="eiendom" {...props}>
Expand Down

0 comments on commit 4a6b9dc

Please sign in to comment.