【问题标题】:Disable spellcheck on all material-ui components禁用所有 material-ui 组件的拼写检查
【发布时间】:2019-04-22 19:26:41
【问题描述】:

有没有办法在material-ui 组件上全局禁用拼写检查?

在使用 material-ui 库之前,我使用了以下 sn-p 来禁用所有新创建的 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 中的组件。因为必须在应用程序范围内禁用拼写检查,所以我正在寻找一种不涉及单独修改每个组件的样式的解决方案。

【问题讨论】:

标签: javascript reactjs material-ui


【解决方案1】:

为此,应将spellCheck 属性提供给输入。

这可以通过以下方式在 Material UI 中完成:

<Input inputProps={{ spellCheck: 'false' }}/>

默认道具可以应用于具有主题的所有输入:

const theme = createMuiTheme({
  props: {
    MuiInput: { inputProps: { spellCheck: 'false' } }
  }
});

...

<MuiThemeProvider theme={theme}>...</MuiThemeProvider>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2016-06-30
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    相关资源
    最近更新 更多