是否有一种方法可以全局禁用material-ui
组件上的拼写检查?
在使用material-ui
库之前,我使用以下代码段禁用了所有新创建的DOM元素的拼写检查:
const disableSpellCheck = function(mutations)
{
const mutationCount = mutations.length;
for (let i = 0; i < mutationCount; i++) {
const mutation = mutations[i];
if (mutation.attributeName === "spellcheck") {
const addedNodes = mutation.addedNodes;
const nodeCount = addedNodes.length;
for (let n = 0; n < nodeCount; n++) {
addedNodes[n].setAttribute("spellcheck", "false");
}
}
}
}
const observer = new MutationObserver(disableSpellCheck);
observer.observe(document.getElementById('root'), {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['spellcheck']
});
这似乎不适用于material-ui
中的组件。因为必须在整个应用范围内禁用拼写检查,所以我正在寻找一种不涉及单独修改每个组件样式的解决方案。
答案 0 :(得分:1)
为此,应为输入提供spellCheck
道具。
这可以在Material UI中通过以下方式完成:
<Input inputProps={{ spellCheck: 'false' }}/>
默认道具可以应用于具有主题的所有输入:
const theme = createMuiTheme({
props: {
MuiInput: { inputProps: { spellCheck: 'false' } }
}
});
...
<MuiThemeProvider theme={theme}>...</MuiThemeProvider>