更改MUI DatePicker对话框的OK文字

发布于 2025-02-13 07:12:08 字数 63 浏览 0 评论 0 原文

如何将datepicker对话框按钮从确定更改为诸如应用之类的内容。 MUI文档没有提供任何帮助我更改标题的道具

How can i change datepicker dialog button text from OK to something like Apply. The MUI docs does not provide any props to help me change the title

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉世弥音 2025-02-20 07:12:08

我正在使用MUI的datepicker v5,以下对我有用:

来自我的软件包的版本:“@mui/x-date-pickers”:“^5.0.16”,

import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
import { DateTime } from 'luxon';

.....


<LocalizationProvider
  dateAdapter={AdapterLuxon}
  localeText={{ cancelButtonLabel: 'Exit', clearButtonLabel: 'None', okButtonLabel: 'Save', todayButtonLabel: 'Set today' }}
>
    <DatePicker
      open={open}
      onOpen={() => setOpen(true)}
      onClose={() => setOpen(false)}
      inputFormat="dd MMM yyyy"
      disableMaskedInput
      value={DateTime.local()}
      onChange={handleChange}
      renderInput={(params) => {
        console.log(params);
        return <TextField {...params} onClick={(e) => setOpen(true)} />;
      }}
      
      componentsProps={{
        actionBar: {
          actions: ["cancel", "clear", "accept", "today"],
        }
      }}

    />
</LocalizationProvider>

  • 您可以通过指定 componentsProps datePicker 在datePicker的日历对话框上指定哪些按钮。显示的按钮的顺序遵循传递给 componentsprops-&gt; actionbar-&gt; action 的序列。在这种情况下,按钮的顺序将是:取消,清除,接受,今天。

  • 您可以通过将 localeText 传递给lotization provider的按钮上的标签:

  • ,所以您会看到这一点日历对话框中的按钮:退出,无,保存,设置

”输入图像描述在这里”

I'm using MUI's datepicker v5, the below works for me:

version from my package.json: "@mui/x-date-pickers": "^5.0.16",

import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
import { DateTime } from 'luxon';

.....


<LocalizationProvider
  dateAdapter={AdapterLuxon}
  localeText={{ cancelButtonLabel: 'Exit', clearButtonLabel: 'None', okButtonLabel: 'Save', todayButtonLabel: 'Set today' }}
>
    <DatePicker
      open={open}
      onOpen={() => setOpen(true)}
      onClose={() => setOpen(false)}
      inputFormat="dd MMM yyyy"
      disableMaskedInput
      value={DateTime.local()}
      onChange={handleChange}
      renderInput={(params) => {
        console.log(params);
        return <TextField {...params} onClick={(e) => setOpen(true)} />;
      }}
      
      componentsProps={{
        actionBar: {
          actions: ["cancel", "clear", "accept", "today"],
        }
      }}

    />
</LocalizationProvider>

  • You can specify which buttons are displayed on the datepicker's calendar dialog by specifying the componentsProps for datepicker. The sequence of the buttons displayed follows the sequence in the array passed to componentsProps->actionBar->actions. In this case, the order of buttons will be: cancel, clear, accept, today.

  • You can change the label on the buttons by passing in localeText to the LocalizationProvider:
    <LocalizationProvider localeText={{ cancelButtonLabel: 'Exit', clearButtonLabel: 'None', okButtonLabel: 'Save', todayButtonLabel: 'Set today' }}>

  • So you will see this buttons in the calendar dialog: Exit, None, Save, Set today

enter image description here

南巷近海 2025-02-20 07:12:08

您只需将俄克拉牌提供给您的datepicker组件即可。

<DatePicker
  okLabel={"Apply"}
  {...props}
/>

You can simply pass okLabel prop to your datepicker component.

<DatePicker
  okLabel={"Apply"}
  {...props}
/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文