Last active
March 22, 2019 12:47
-
-
Save adipascu/10f919b3daa18c2221de934f34f22bec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This fixes issues with: | |
- devices that incorrectly state they support hover (Samsung Galaxy Note 9, SM-N960F, Android 8.1, Chrome 73) | |
- devices that do not support media queries for hover, but they are enabled by default in Material-UI | |
*/ | |
export default { | |
onProcessStyle(style, rule) { | |
if (rule.type !== 'style') return style; | |
let newProps = []; | |
for (const prop in style) { | |
const isNestedConditional = prop === '@media (hover: none)'; | |
if (isNestedConditional) { | |
newProps = newProps.concat(Object.entries(style[prop])); | |
delete style[prop]; | |
} else if (prop[0] === '@' && prop.includes('hover')) { | |
throw new Error(`Could not process media query ${prop}`); | |
} | |
} | |
if (newProps.length > 0) { | |
return { ...style, ...Object.fromEntries(newProps) }; | |
} | |
return style; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment