Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DatePicker]DatePicker disabledTime 失效 #199

Open
xiaojianbu opened this issue Nov 4, 2021 · 2 comments
Open

[DatePicker]DatePicker disabledTime 失效 #199

xiaojianbu opened this issue Nov 4, 2021 · 2 comments
Assignees
Labels
feature request Request new feature

Comments

@xiaojianbu
Copy link

Which Component 出现bug的组件

  • DatePicker

semi-ui version

  • latest

Expected result 期望的结果是什么

  • disabledTime 禁止时间生效

Actual result 实际的结果是什么

  • disabledTime 禁止时间失效

Steps to reproduce 复现步骤

  • 先设置时间为第二天的下午5-6点
  • 再切换日期为当天
  • 禁止时间失效

Reproducible code 复现代码

import React from 'react';
import { DatePicker } from '@ies/semi-ui-react';
import * as dateFns from 'date-fns';

class App extends React.Component {
    constructor(props = {}) {
        super(props);

        this.today = () => new Date();

        this.disabledTime = date =>
            dateFns.isToday(date)
                ? {
                      disabledHours: () => [17, 18],
                  }
                : null;
    }

    render() {
        return (
                <div>
                    <h4>禁用时间:禁用今天下午5-6点</h4>
                    <DatePicker type="dateTime" hideDisabledOptions={false} disabledTime={this.disabledTime} />
                </div>
        );
    }
}

Additional information 补充说明

  • 遇到这个bug的业务场景、上下文、或者你的需求场景
@xiaojianbu xiaojianbu added the bug Something isn't working label Nov 4, 2021
@xiaojianbu xiaojianbu changed the title DatePicker disabledTime 失效 [DatePicker]DatePicker disabledTime 失效 Nov 4, 2021
@shijiatongxue shijiatongxue added this to the v2.1 milestone Nov 5, 2021
@shijiatongxue
Copy link
Collaborator

目前的交互行为不好用。disabledTime 只对时间生效,无法控制日期是否可以选择。可以先通过下面的方式实现这个目标 o(╥﹏╥)o

() => {
    const [value, setValue] = useState();
    const disabledTime = date =>
        dateFns.isToday(date)
            ? {
                disabledHours: () => [17, 18],
            }
            : null;

    const disabledDate = date => {
        const h = dateFns.isDate(value) && value.getHours() || 0;
        const d = date.getDate();
        console.log(d, h);

        if (dateFns.isToday(date) && [17, 18].includes(h)) {
            return true;
        } else {
            return false;
        }
    };

    const handleChange = (date) => {
        setValue(date);
    };

    return (
        <div>
            <h4>禁用时间:禁用今天下午5-6点</h4>
            <DatePicker type="dateTime" onChange={handleChange} disabledDate={disabledDate} disabledTime={disabledTime} />
        </div>
    );
}

@shijiatongxue
Copy link
Collaborator

建议优化 disabledDate 逻辑,如果已选时间在禁用范围内,则日期也不可选(For Semi RD)。

@shijiatongxue shijiatongxue self-assigned this Nov 9, 2021
@shijiatongxue shijiatongxue removed this from the v2.1 milestone Nov 17, 2021
@shijiatongxue shijiatongxue reopened this Jan 30, 2023
@shijiatongxue shijiatongxue added feature request Request new feature and removed bug Something isn't working labels Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request new feature
Projects
None yet
Development

No branches or pull requests

2 participants