首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Popper.js改性剂

Popper.js改性剂
EN

Stack Overflow用户
提问于 2021-09-09 13:06:30
回答 2查看 2.9K关注 0票数 1

在我们的Reactive&Typeescript应用程序中,我们使用的是,它本身也使用popper.js。我正在尝试分配PopperModifiers,如下所示:https://reactdatepicker.com/#example-configure-popper-properties

但是,即使我们使用的是示例中的内容,我们也会得到以下类型记录错误:

代码语言:javascript
复制
Overload 1 of 2, '(props: ReactDatePickerProps |
Readonly<ReactDatePickerProps>): ReactDatePicker', gave the following
error.
     Type '({ name: string; options: { offset: number[]; }; } | { name: string; options: { rootBoundary: string; tether: false; altAxis: true;
 }; })[]' is not assignable to type 'Modifiers'.
       Types of property 'shift' are incompatible.
         Type '() => { name: string; options: { offset: number[]; }; } | { name: string; options: { rootBoundary: string; tether: false;
 altAxis: true; }; } | undefined' has no properties in common with type
 'BaseModifier'.   Overload 2 of 2, '(props: ReactDatePickerProps,
 context: any): ReactDatePicker', gave the following error.
     Type '({ name: string; options: { offset: number[]; }; } | { name: string; options: { rootBoundary: string; tether: false; altAxis: true;
 }; })[]' is not assignable to type 'Modifiers'.
       Types of property 'shift' are incompatible.
         Type '() => { name: string; options: { offset: number[]; }; } | { name: string; options: { rootBoundary: string; tether: false;
 altAxis: true; }; } | undefined' has no properties in common with type
 'BaseModifier'.ts(2769)

为什么我们不能像在示例中那样分配修饰符数组呢?有谁有一个示例说明如何在类型记录中使用popper修饰符?

编辑:真正让我困惑的是Popper.Modifiers类型的这个属性:

代码语言:javascript
复制
[name: string]: (BaseModifier & Record<string, any>) | undefined;

有人能在这里解释一下吗?

EDI2:这是我们当前实现的react datepicker,问题是popperModifier属性:

代码语言:javascript
复制
 <DatePicker
                selected={this.value ? new Date(this.value) : null}
                onChange={this.onChange}
                peekNextMonth
                showMonthDropdown={this.props.showMonthDropdown}
                showYearDropdown={this.props.showYearDropdown}
                dropdownMode={this.props.dropdownMode}
                dateFormat={i18next.t("common.dateformat")}
                popperPlacement="bottom-end"
                popperClassName="da-datepicker-popup"
                popperModifiers={[
                    {
                      name: "offset",
                      options: {
                        offset: [5, 10],
                      },
                    },
                    {
                      name: "preventOverflow",
                      options: {
                        rootBoundary: "viewport",
                        tether: false,
                        altAxis: true,
                      },
                    },
                  ]}
                includeDates={this.props.availableDates}
                adjustDateOnChange={false}
                yearDropdownItemNumber={this.props.yearDropdownItemNumber}
                maxDate={this.props.maxDate}
                minDate={this.props.minDate}
                strictParsing
                portalId="root-portal" />
EN

回答 2

Stack Overflow用户

发布于 2021-10-01 12:55:19

您需要安装类型定义。

请参阅:https://www.npmjs.com/package/@types/react-datepicker

票数 1
EN

Stack Overflow用户

发布于 2021-12-24 09:08:52

您应该使用react-popper文档。

https://popper.js.org/docs/v2/modifiers/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69118789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档