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

[Calendar] What's the exact type of selectedDates in the Calendar component #1730

Closed
SunnyWind opened this issue May 22, 2020 · 11 comments · Fixed by #2424
Closed

[Calendar] What's the exact type of selectedDates in the Calendar component #1730

SunnyWind opened this issue May 22, 2020 · 11 comments · Fixed by #2424

Comments

@SunnyWind
Copy link

In the storybook, it says the type of selectedDates property is unknown[], which is very unclear.
image

On the other side, my editor tells me the type of the selectedDates is number[].
image

If I set the selectedDates to [Date.now()/1000], I'll get an error:
image
image

What kind of data should I pass to the Calendar component if I want to specify an initial date?

@MarcusNotheis
Copy link
Collaborator

Hi @SunnyWind,

I'm not sure what the correct prop type is to be honest - I've created an issue (#1677) to clarify.

Best regards,
MArcus

@MarcusNotheis MarcusNotheis self-assigned this May 22, 2020
@MarcusNotheis
Copy link
Collaborator

Hey @SunnyWind

I'm just copy-pasting Vladi's answer from the Web Components Team.
Looks like you have to attach a ref to the Calender and set the current date via Javascript in a useEffect or componentDidMount/Update. Could you please explain what your use case of the Calendar is?

Best regards,
Marcus

Indeed, ui5-calendar is intended to be a lower-level component, mainly used by other components. Therefore its API is not as user-friendly.

UI5 Web Components metadata entities of type Object or of multiple: true (hence Array) cannot be passed via attributes, but only via HTML properties. You can't bind them declaratively via React, only with JS.

myCalendar.selectedDates = [1588464000];

is what would work.

But if you have a strong case, we can redo the calendar to have calendar date items or something of that sort that you can pass as children.

Regards,
Vladi

Originally posted by @vladitasev in #1677 (comment)

@SunnyWind
Copy link
Author

Thanks for your answer, which can solve my problem.

I want to replace the current calendar plugin (which is a YUI plugin) on our website with ui5-webcomponent calendar.

Just replacing the calendar widget will be easier compared with using the DatePicker (Less modifications to HTML construct).

@MarcusNotheis
Copy link
Collaborator

I think this is a valid use case to be honest - @vladitasev does this justify a rework of the Calender to have a more declarative API?

@MarcusNotheis
Copy link
Collaborator

As this issue is focusing on a UI5 Web Component, I'll forward this issue to the respective repository.

@MarcusNotheis MarcusNotheis transferred this issue from SAP/ui5-webcomponents-react Jun 3, 2020
@MarcusNotheis MarcusNotheis removed their assignment Jun 4, 2020
@vladitasev vladitasev added enhancement New feature or request feature request labels Jun 9, 2020
@vladitasev
Copy link
Contributor

Hi @SunnyWind @MarcusNotheis

Yes, I think it makes sense to promote the Calendar as a real standalone component. We'll estimate what kind of effort will be required and we'll update you here.

Regards

@vladitasev
Copy link
Contributor

The goal of the story is to make the calendar usable standalone. This would require all APIs to be re-evaluated and changed where necessary, it should have all necessary events, proper docs.

@ilhan007 ilhan007 removed Teams story enhancement New feature or request labels Aug 12, 2020
@ilhan007
Copy link
Member

ilhan007 commented Sep 3, 2020

Phase 1 - Make the ui5-calendar standalone and public component.

There is а private ui5-calendar web component that is internally used by the DatePicker, DateTimePicker and DateRangePicker. The task is to make it public, to ensure it is completely usable standalone. But also to review the current API
and make it more user friendly if possible.

1. API to support

  • Props
    minDate (already exists, public)
    maxDate (already exists, public)
    primaryCalendarType (already exists, public)
    selectedDates(already exists, public)
    hideWeekNumbers (already exists, public)
    selection: {
    type: CalendarSelection // enum of ["Single" (default), "Multiple" and "Range"]
    } (new, should be public)

  • Events
    selected-dates-change (already exists, public)

Note: timestamp and formatPattern should be private.

2. We would like to have single range selection.

Currently if you set the following:

calComponent.selectedDates = [1600041600, 1600128000, 1600214400, 1600300800, 1600387200, 1600473600, 1600560000, 1600646400, 1600732800, 1600819200, 1600905600]

You will get:

Screenshot 2020-09-03 at 4 17 22 PM

But, it is not possible to get it via user interaction. We have DateRangePicker, so some of the logic should be extracted from the DateRangePicker and implemented on Calendar level and then DateRangePicker would rely on the Calendar for this. If both components should communicate in this regards, it should be done via events.

3. Upon TAB the focus should move to the "selected day" or "today".
Currently the button, that opens the Month Picker is the 1st element to get the focus. But as far as I researched, the order should be: the "selected day/today", Month Picker button and Year Picker button.

4. The components (DatePicker, DateTimePicker and DateRangePicker) using the Calendar should adopt the API changes (if any)

5. The component has a test page (Calendar.html) that need to be improved:

  • Bind for the selected-dates-change event,
    display the result in an for example
  • Showcase the minDate, maxDate and hideWeekNumbers properties.
  • Showcase the Single, Multiple and Range selection modes.

6. The component has a test spec (Calendar.spec.js) that might has to be adjusted.

7. Properly document - add overview section, import info, etc (refer to the existing components and the openui5 equivalent for the text), remove all @ since tags and provide just one for the entire class @ since 1.0.0-rc.10

8. Playground sample - create Calendar.sample.html with few examples that showcase the component

@ilhan007
Copy link
Member

ilhan007 commented Sep 3, 2020

Hello @SunnyWind

we introduced the Calendar as standalone component (ui5-calendar). The component is merged into the master, not yet released. This was the first step to achieve the goal. Now, we created a separate issue "Calendar: Declarative way of setting the selected days" that we will full-fill your request completely. You can track the progress here: #2528

BR,
ilhan

@ilhan007 ilhan007 added this to the 1.0.0-rc.11 milestone Oct 8, 2020
unazko added a commit to unazko/ui5-webcomponents that referenced this issue Oct 30, 2020
ilhan007 pushed a commit that referenced this issue Nov 30, 2020
"CalendarSelection" enumeration is introduced with single, multiple and
range selection modes.
DayPicker component uses the new "CalendarSelection" class,
in order to provide support for the three selection modes.
Selection of multiple dates can be configured via the "selection"
property of the Calendar component. Holding control keyboard key doesn't
allow multiple dates selection.
The logic for selecting a range of dates is moved from
the DateRangePicker component into the DayPicker component.
Selecting a range of dates via mouse now doesn't cause flickering
on the hovered items.
Updating the selected date range into the DateRangePicker component
input field is now reflected visually, when the popover is opened.
DateRangePicker now works properly with only start date of the range
typed into the input field.
Calendar navigation is now compliant with the specification.
Playground sample is created.

Fixes #1730
@ilhan007
Copy link
Member

ilhan007 commented Nov 30, 2020

Hello @SunnyWind

we introduced the Calendar as standalone component (ui5-calendar). The component is merged into the master #2424, it is not yet released. This was the first step to achieve the goal. Now, we created a separate issue "Calendar: Declarative way of setting the selected days" that we will full-fill your request completely. You can track the progress here: #2528

BR,
ilhan

@SunnyWind
Copy link
Author

Hi @ilhan007

Fantastic 👍

I use ui5-webcomponent-react instead of the base lib. I'll try it if the new feature is applied in that library.

BRs,
Ryan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants