Skip to content

Instantly share code, notes, and snippets.

@adipascu
Last active March 22, 2019 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adipascu/10f919b3daa18c2221de934f34f22bec to your computer and use it in GitHub Desktop.
Save adipascu/10f919b3daa18c2221de934f34f22bec to your computer and use it in GitHub Desktop.
/*
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