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

fix(Calendar): fix watch 'defaultDate' error #13077

Merged
merged 2 commits into from
Sep 8, 2024

Conversation

pany-ang
Copy link
Contributor

当 defaultDate 为 undefined 时,现有的 watch 会将其重置为 null,逻辑如下:

    watch(
      () => props.defaultDate,
      (value = null) => {
        currentDate.value = value;
        scrollToCurrentDate();
      },
    );

而在该日历组件中,undefined 表示「今天」,null 表示 「不选择」。如果业务层将 defaultDate 重置为 undefined,这时候日历组件将会表现为「不选择」,业务层必须手动调用一次 reset 方法才能实现日历上选中「今天」

所以该侦听器逻辑应该是:

    watch(
      () => props.defaultDate,
      (value) => {
        if (value === undefined) {
          value = getInitialDate();
        }
        currentDate.value = value;
        scrollToCurrentDate();
      },
    );

简化一下:

    watch(
      () => props.defaultDate,
      (value) => {
        reset(value);
      },
    );

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.67%. Comparing base (eef8e0b) to head (0b27cf3).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13077      +/-   ##
==========================================
+ Coverage   89.66%   89.67%   +0.01%     
==========================================
  Files         257      257              
  Lines        6987     6985       -2     
  Branches     1724     1724              
==========================================
- Hits         6265     6264       -1     
+ Misses        382      381       -1     
  Partials      340      340              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pany-ang pany-ang changed the title fix(Calendar): Fix watch 'defaultDate' error fix(Calendar): fix watch 'defaultDate' error Aug 22, 2024
Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方便加个单元测试嘛?

@pany-ang
Copy link
Contributor Author

单测已添加

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@chenjiahan chenjiahan merged commit 11da88a into youzan:main Sep 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants