Skip to content

docs(datetime): add multiple selection playground #2442

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

Merged
merged 5 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/api/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import ShowingConfirmationButtons from '@site/static/usage/datetime/buttons/show
import CustomizingButtons from '@site/static/usage/datetime/buttons/customizing-buttons/index.md';
import CustomizingButtonTexts from '@site/static/usage/datetime/buttons/customizing-button-texts/index.md';

import MultipleDateSelection from '@site/static/usage/datetime/multiple/index.md';

import Theming from '@site/static/usage/datetime/theming/index.md';

<head>
Expand Down Expand Up @@ -237,6 +239,16 @@ import Wheel from '@site/static/usage/datetime/presentation/wheel/index.md';

<Wheel />

## Multiple Date Selection

If the `multiple` property is set to `true`, multiple dates can be selected from the calendar picker. Clicking a selected date will deselect it.

:::note
This property is only supported when using `presentation="date"` and `preferWheel="false"`.
:::

<MultipleDateSelection />

## Titles

By default, `ion-datetime` does not show any header or title associated with the component. Developers can use the `showDefaultTitle` property to show the default title/header configuration. They can also use the `title` slot to customize what is rendered in the header.
Expand Down
7 changes: 7 additions & 0 deletions static/usage/datetime/multiple/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```html
<ion-datetime
presentation="date"
[multiple]="true"
[value]="['2022-06-03', '2022-06-13', '2022-06-29']"
></ion-datetime>
```
31 changes: 31 additions & 0 deletions static/usage/datetime/multiple/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Datetime</title>
<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@6/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@6/css/ionic.bundle.css" />
<style>
ion-datetime {
width: 350px;
}
</style>
</head>
<body>
<ion-app>
<ion-content>
<div class="container">
<ion-datetime presentation="date" multiple="true"></ion-datetime>
</div>
</ion-content>
</ion-app>

<script>
const datetime = document.querySelector('ion-datetime');
datetime.value = ['2022-06-03', '2022-06-13', '2022-06-29'];
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions static/usage/datetime/multiple/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';
import react from './react.md';
import vue from './vue.md';
import angular from './angular.md';

<Playground size="medium" code={{ javascript, react, vue, angular }} src="usage/datetime/multiple/demo.html" />
8 changes: 8 additions & 0 deletions static/usage/datetime/multiple/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```html
<ion-datetime presentation="date" multiple="true"></ion-datetime>

<script>
const datetime = document.querySelector('ion-datetime');
datetime.value = ['2022-06-03', '2022-06-13', '2022-06-29'];
</script>
```
20 changes: 20 additions & 0 deletions static/usage/datetime/multiple/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```tsx
import React, { useRef, useEffect } from 'react';
import { IonDatetime } from '@ionic/react';

function Example() {
const datetime = useRef<null | HTMLIonDatetimeElement>(null);

useEffect(() => {
if(!datetime.current) return;
datetime.current.value = ['2022-06-03', '2022-06-13', '2022-06-29'];
}, []);
Comment on lines +6 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done to get around this issue, which also applies here: ionic-team/ionic-framework#25041

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update that issue to mention it will affect ion-datetime with multiple? Also, should we add a comment in the playground so in the future when that issue is resolved, we can update this example and remove this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call 👀 I updated the issue and will add a tech debt ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ticket made: https://ionic-cloud.atlassian.net/browse/FW-1872 I skipped adding the comment since I didn't want it to show up in the actual docs site (and putting it in demo.html felt weird when it's not relevant to that), but I think the Jira ticket should be good enough for tracking this.


return <IonDatetime
ref={datetime}
presentation="date"
multiple={true}
></IonDatetime>;
}
export default Example;
```
18 changes: 18 additions & 0 deletions static/usage/datetime/multiple/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```html
<template>
<ion-datetime
presentation="date"
:multiple="true"
:value="['2022-06-03', '2022-06-13', '2022-06-29']"
></ion-datetime>
</template>

<script lang="ts">
import { IonDatetime } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: { IonDatetime },
});
</script>
```