Skip to content

Commit

Permalink
Merge pull request #96 from moneyadviceservice/patch-4153-IE11-flex-b…
Browse files Browse the repository at this point in the history
…asis-css-fix

Patch 4153 ie11 flex basis css fix
  • Loading branch information
benlovell authored Mar 16, 2022
2 parents cbf234a + 6ed4218 commit 0f2b385
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneypensionservice/directories",
"version": "2.0.2",
"version": "2.0.4",
"description": "Directories React Component Library",
"homepage": "https://moneyadviceservice.github.io/react_library/",
"repository": {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ export const SPACING_SIZES = [
'xlarge',
]

// detect IE11 only browsers
export const isBrowserIE11 = !!window.MSInputMethodContext && !!document.documentMode;
36 changes: 17 additions & 19 deletions src/utils/helpers/flexbox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css } from 'styled-components'
import { breakpoints, dimensions, isBrowserIE11 } from '../constants'
import { breakpoints, dimensions } from '../constants'
import { breakpointStyle } from './responsive'

/**
Expand All @@ -10,15 +10,15 @@ import { breakpointStyle } from './responsive'
*/
export const flexStyle = sizeProp => {
if (typeof sizeProp === 'number') {
// IE11 fix
if(isBrowserIE11) {
return css`
flex-basis: auto;
width: ${(sizeProp / 12) * 100}%;
`
}
// IE11 media query - flex-basis fix: auto and width
// @supports targets modern browsers (ignored by IE11)
return css`
flex-basis: ${(sizeProp / 12) * 100}%;
flex-basis: auto;
width: ${(sizeProp / 12) * 100}%;
@supports (display: grid) {
flex-basis: ${(sizeProp / 12) * 100}%;
width: unset;
}
`
} else if (sizeProp === 'auto') {
return css`
Expand All @@ -28,19 +28,17 @@ export const flexStyle = sizeProp => {
} else {
return dimensions.map(d => {
if (breakpoints[d] && sizeProp[d] && sizeProp[d] !== 'auto') {
// IE11 fix
if(isBrowserIE11) {
return css`
${breakpointStyle(
breakpoints[d],
`flex-basis: auto; width: ${(sizeProp[d] / 12) * 100}%;`
)}
`
}
// IE11 media query - flex-basis fix: auto and width
// @supports targets modern browsers (ignored by IE11)
return css`
${breakpointStyle(
breakpoints[d],
`flex-basis: ${(sizeProp[d] / 12) * 100}%;`
`flex-basis: auto; width: ${(sizeProp[d] / 12) * 100}%;
@supports (display: grid) {
flex-basis: ${(sizeProp[d] / 12) * 100}%;
width: unset;
}
`
)}
`
} else if (breakpoints[d] && sizeProp[d] === 'auto') {
Expand Down

0 comments on commit 0f2b385

Please sign in to comment.