-
Notifications
You must be signed in to change notification settings - Fork 3.1k
docs(item): add best practices and usage guides #3123
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
Changes from 65 commits
7d0321a
aedc307
cdce63e
00a9c73
05ee5c6
d25e0f4
bbe422b
9bd8809
b02c744
073cb54
e040fc8
d45dcc7
c0f8940
a0e4a71
81cf625
a0e5496
dffa720
ed6fdea
4ae34ef
f2c4f2d
59af34c
4a1b7f8
427e6aa
0bc5327
7ded04a
a6e67f8
3e58f37
2281c83
d63328f
f79d81b
9d5d252
9210d5f
de3e005
db2f997
b1a9c33
d0cd106
d944f10
b58609c
543c0a7
8f26d53
3316920
684b880
579b4b4
ba84925
e2fa31f
0f6f3f2
c1c43f6
326168e
008f65b
ff9dd00
ecaea65
3b0efb7
8888a48
2025a7a
24b7931
99967e0
e96ddc9
b367c2b
246ce2b
7512d9c
835ed63
a7a4657
13b1b92
4f54f99
43e86dc
8e75c43
d163d0e
596ba7c
c86c887
9d34ccf
8384b6b
068dd1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,9 @@ import Parts from '@ionic-internal/component-api/v7/item/parts.md'; | |||||
import CustomProps from '@ionic-internal/component-api/v7/item/custom-props.md'; | ||||||
import Slots from '@ionic-internal/component-api/v7/item/slots.md'; | ||||||
|
||||||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||||||
import BestPracticeFigure from '@components/global/BestPracticeFigure'; | ||||||
|
||||||
<head> | ||||||
<title>ion-item: Input, Edit, or Delete iOS and Android Item Elements</title> | ||||||
<meta name="description" content="ion-item elements for iOS/Android contain text, icons, images, and other custom elements. They're placed in a list and can be input, deleted, edited, and more." /> | ||||||
|
@@ -17,7 +20,8 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill'; | |||||
|
||||||
<EncapsulationPill type="shadow" /> | ||||||
|
||||||
Items are elements that can contain text, icons, avatars, images, inputs, and any other native or custom elements. Generally they are placed in a [list](./list) with other items. Items can be swiped, deleted, reordered, edited, and more. | ||||||
Items are elements that can contain text, icons, avatars, images, inputs, and any other native or custom elements. Items should only be used as rows in a [List](./list) with other items. Items can be swiped, deleted, reordered, edited, and more. | ||||||
|
||||||
|
||||||
## Basic Usage | ||||||
|
||||||
|
@@ -28,6 +32,125 @@ import Basic from '@site/static/usage/v7/item/basic/index.md'; | |||||
<Basic /> | ||||||
|
||||||
|
||||||
## Content Types | ||||||
|
||||||
While items in a list take many forms, they typically support 5 different content types: supporting visuals, text, metadata, actions, and controls. However, not all of these content types should be used together at the same time. The following guide shows the different content types as well as how to properly utilize them in an application. | ||||||
|
||||||
### Supporting Visuals | ||||||
|
||||||
Supporting visuals are decorative icons or other adornments for an item. Common examples of supporting visuals are [Avatars](./avatar), [Icons](./icon), and [Thumbnails](./thumbnail). Since this content is not required to understand the intent of the item, it is typically hidden from screen readers using `aria-hidden="true"`. | ||||||
|
||||||
If a visual is required to interact with the item, such as an icon button, then the visual is an [action](#actions) not a supporting visual. | ||||||
|
||||||
<BestPracticeFigure | ||||||
text="Supporting visuals should be rendered in a consistent manner. This makes the information in each item easier to parse." | ||||||
doText="Align visuals on the same side in a list" | ||||||
dontText="Don't render visuals with different alignments in the same list" | ||||||
doImage={<img alt="A list with several items. Each item has an icon and visible text describing the item. The icon in each item is rendered at the start of the line." src={useBaseUrl('img/item/visuals-do.jpg')} />} | ||||||
dontImage={<img alt="A list with several items. Each item has an icon and visible text describing the item. Some icons are rendered at the start of the line, and some icons are rendered at the end of the line" src={useBaseUrl('img/item/visuals-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
In the example below, we are creating two lists with supporting visuals. The first list uses icons, and the second list uses avatars. The visuals are decorative, so they all have `aria-hidden="true"`. Additionally, they are presented consistently in the `start` slot. | ||||||
brandyscarney marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
import SupportingVisuals from '@site/static/usage/v7/item/content-types/supporting-visuals/index.md'; | ||||||
|
||||||
<SupportingVisuals /> | ||||||
averyjohnston marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
### Text | ||||||
|
||||||
The text content type includes form control labels or other visible text. This text serves to indicate the intent of the item. Try to keep the text short and to the point. | ||||||
|
||||||
<BestPracticeFigure | ||||||
text={<>If you find that you need a few more sentences to clarify the item's purpose, consider moving the additional sentences to a <a href={useBaseUrl('api/note')}>Note</a> at the bottom of the list. Adding the item to its own list makes it clear which item the text is associated with.</>} | ||||||
doText="Move long text outside of the list" | ||||||
dontText="Don't try to fit long text in an item" | ||||||
doImage={<img alt="A list with an item that contains a checked checkbox indicating the user wants to receive emails. Text describing how often the user will receive emails as well as how to unsubscribe from emails is placed underneath the list." src={useBaseUrl('img/item/long-text-do.jpg')} />} | ||||||
dontImage={<img alt="A list with an item that contains a checked checkbox indicating the user wants to receive emails. Text describing how often the user will receive emails as well as how to unsubscribe from emails is placed as a single paragraph inline with the checkbox, making the text hard to read and increasing the height of the item." src={useBaseUrl('img/item/long-text-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
In the example below, we are creating a list with different types of text. The "First Name" and "Last Name" labels serve to indicate what to type into the text inputs. | ||||||
|
||||||
The "Allow Notifications" label on the toggle has additional text underneath it that notes users can disable notifications. Since this text is short, it is placed inside of the item. | ||||||
|
||||||
Below that list is another list containing a textarea with a [Note](./note) containing long text underneath. The textarea was placed in its own list to make it apparent that the long text is associated with the textarea and not any other fields. | ||||||
|
||||||
import Text from '@site/static/usage/v7/item/content-types/text/index.md'; | ||||||
|
||||||
<Text /> | ||||||
|
||||||
### Metadata | ||||||
|
||||||
Metadata provides additional context for an item such as status text or counts. Components like [Badge](./badge) or [Note](./note) are great ways of showing metadata. | ||||||
|
||||||
<BestPracticeFigure | ||||||
text="Limit the amount of metadata you include to only the most relevant information." | ||||||
doText="Add only the most important metadata" | ||||||
brandyscarney marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
dontText="Don't add too much metadata as it can overwhelm or confuse the user." | ||||||
doImage={<img alt="A list that contains several items, each representing a different to-do list. A count of how many tasks in each to-do list is placed at the end of each item." src={useBaseUrl('img/item/metadata-relevant-do.jpg')} />} | ||||||
dontImage={<img alt="A list that contains several items, each representing a different to-do list. Two counts are placed at the end of each item: One count that states the total number of tasks, and another count that states the total number of tasks that are due today." src={useBaseUrl('img/item/metadata-relevant-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
<BestPracticeFigure | ||||||
text="Developers should also consider how important the metadata is. Drawing attention to the metadata may be helpful for the user or it may distract them from the more important information depending on the use case." | ||||||
doText="Prioritize the most important content." | ||||||
cautionText="Prioritized metadata may distract from other important content." | ||||||
doImage={<img alt="A list that contains several items, each representing a different to-do list. A count of how many tasks in each to-do list is placed at the end of each item." src={useBaseUrl('img/item/metadata-relevant-do.jpg')} />} | ||||||
cautionImage={<img alt="A list that contains several items, each representing a different to-do list. A count of how many tasks in each to-do list is placed at the end of each item. However, the count is highlighted in blue which draws the user's attention away from the name of the to-do list." src={useBaseUrl('img/item/metadata-important-caution.jpg')} />} | ||||||
/> | ||||||
|
||||||
In the example below, we are creating two lists with different kinds of metadata. The first list uses [Note](./note) to show how many tasks are in each to-do list. | ||||||
|
||||||
The second list mimics the iOS Mail app to show an inbox. This list makes use of custom metadata including an "unread message" indicator in the "start" slot as well as a timestamp and custom detail icon in the "end" slot. The "unread message" indicator is highlighted in blue to draw the user's attention to the unread messages, while the timestamp is more subtle. | ||||||
|
||||||
import Metadata from '@site/static/usage/v7/item/content-types/metadata/index.md'; | ||||||
|
||||||
<Metadata /> | ||||||
|
||||||
### Actions | ||||||
|
||||||
Actions are interactive elements that do something when you activate them. An item can have multiple actions displayed on a line. However, developers should ensure that each action's tap target is large enough to be usable. | ||||||
|
||||||
<BestPracticeFigure | ||||||
text={<>Developers should avoid creating <a href="https://dequeuniversity.com/rules/axe/4.4/nested-interactive">nested interactives</a> which can break the user experience with screen readers. For example, developers should avoid adding a button inside the main content of the Item if the <code>button</code> property is set to <code>true</code>. Additionally, developers should use the <a href={useBaseUrl('api/item-sliding')}>Item Sliding</a> component if they need to show more than two actions.</>} | ||||||
doText={<>Use an <a href={useBaseUrl('api/item-sliding')}>Item Sliding</a> to reveal multiple actions by swiping on the Item.</>} | ||||||
dontText="Don't put too many actions on a single item." | ||||||
liamdebeasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
doImage={<img alt="A list that contains several items, each representing a contact. Each item has text that states the contact's name as well as several actions including pinning the contact, sharing the contact, and deleting the contact. These actions are revealed by swiping on the item." src={useBaseUrl('img/item/actions-do.jpg')} />} | ||||||
dontImage={<img alt="A list that contains several items, each representing a contact. Each item has text that states the contact's name as well as several actions including pinning the contact, sharing the contact, and deleting the contact. The actions are placed directly on the item. Since there are so many actions, some of the text is cut off." src={useBaseUrl('img/item/actions-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
In the example below, we are creating a list of contacts. Each item is a stubbed button intended to bring you to the full contact page for that item. There are additional actions associated with each item that users can reveal by swiping on the item. | ||||||
|
||||||
import Actions from '@site/static/usage/v7/item/content-types/actions/index.md'; | ||||||
|
||||||
<Actions /> | ||||||
|
||||||
### Controls | ||||||
|
||||||
Controls are form components such as checkboxes, inputs, radios, and more. Each item in a list should have at most two controls due to screen space constraints. | ||||||
|
||||||
<BestPracticeFigure | ||||||
text={<>Metadata such as helper text or character counts should not be used on form controls in list views. If such metadata is needed, the form control should be placed outside of a list. Alternatively, the context can be placed in a <a href="useBaseUrl('api/note')">Note</a> at the bottom of the list.</>} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Shouldn't this be the metadata out of the list not the form control? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case the helper text or characters counts refers to properties on You'd need to move the entire input in order to continue using this metadata There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. It's a bit confusing with the image that follows. I expected it to be related to moving the text that says There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Developers have two options for using metadata with form controls:
We have an example of 1 but not of item 2. I'll work on adding item 2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in c86c887 |
||||||
doText="Place metadata for inputs at the end of a list." | ||||||
dontText="Don't put metadata for inputs in the list as it can make the list hard to read." | ||||||
doImage={<img alt="There is one list of inputs. One of the inputs is a password input with text below the input that says 'Password must be at least 16 characters'. However, this text is placed directly above another input, so it's not immediately clear which input the text is associated with." src={useBaseUrl('img/item/controls-metadata-do.jpg')} />} | ||||||
dontImage={<img alt="There are two lists of inputs. The first list contains a password input. Below that list contains text that says 'Password must be at least 16 characters'. The second list contains an email input. This second list is separated so the password length requirement text is clearly associated with the password input above." src={useBaseUrl('img/item/controls-metadata-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
<BestPracticeFigure | ||||||
text={<>Items should typically have no more than two controls. If you need more controls, consider adding the additional controls in a <a href="useBaseUrl('api/modal')">Modal</a> that is accessible from the item.</>} | ||||||
doText="Move additional controls to a submenu accessible from the item." | ||||||
dontText="Don't use more than two controls within an item." | ||||||
doImage={<img alt="There is one list of inputs. One of the inputs is a password input with text below the input that says 'Password must be at least 16 characters'. However, this text is placed directly above another input, so it's not immediately clear which input the text is associated with." src={useBaseUrl('img/item/controls-count-do.jpg')} />} | ||||||
dontImage={<img alt="There are two lists of inputs. The first list contains a password input. Below that list contains text that says 'Password must be at least 16 characters'. The second list contains an email input. This second list is separated so the password length requirement text is clearly associated with the password input above." src={useBaseUrl('img/item/controls-count-dont.jpg')} />} | ||||||
/> | ||||||
|
||||||
In the example below, we are creating a list of to-do tasks. Each item has a checkbox and an input. The checkbox lets the user mark a task as complete, and the input lets the user change the name of the task. | ||||||
|
||||||
import Controls from '@site/static/usage/v7/item/content-types/controls/index.md'; | ||||||
|
||||||
<Controls /> | ||||||
|
||||||
|
||||||
## Clickable Items | ||||||
|
||||||
An item is considered "clickable" if it has an `href` or `button` property set. Clickable items have a few visual differences that indicate they can be interacted with. For example, a clickable item receives the ripple effect upon activation in `md` mode, has a highlight when activated in `ios` mode, and has a [detail arrow](#detail-arrows) by default in `ios` mode. | ||||||
|
@@ -69,16 +192,6 @@ import Lines from '@site/static/usage/v7/item/lines/index.md'; | |||||
|
||||||
<Lines /> | ||||||
|
||||||
|
||||||
## Media Items | ||||||
|
||||||
[Avatars](./avatar) and [Thumbnails](./thumbnail) can be slotted inside of an item. This is useful when making lists of images and text. | ||||||
|
||||||
import Media from '@site/static/usage/v7/item/media/index.md'; | ||||||
|
||||||
<Media /> | ||||||
|
||||||
|
||||||
## Buttons in Items | ||||||
|
||||||
Buttons are styled smaller inside of items than when they are outside of them. To make the button size match buttons outside of an item, set the `size` attribute to `"default"`. | ||||||
|
@@ -87,14 +200,6 @@ import Buttons from '@site/static/usage/v7/item/buttons/index.md'; | |||||
|
||||||
<Buttons /> | ||||||
|
||||||
|
||||||
## Icons in Items | ||||||
|
||||||
import Icons from '@site/static/usage/v7/item/icons/index.md'; | ||||||
|
||||||
<Icons /> | ||||||
|
||||||
|
||||||
## Item Inputs | ||||||
|
||||||
import Inputs from '@site/static/usage/v7/item/inputs/index.md'; | ||||||
|
@@ -132,6 +237,14 @@ import InputHighlight from '@site/static/usage/v7/item/theming/input-highlight/i | |||||
|
||||||
<InputHighlight /> | ||||||
|
||||||
## Guidelines | ||||||
|
||||||
The following guidelines will help ensure your list items are easy to understand and use. | ||||||
|
||||||
1. Items should only be used inside of [Lists](./list). | ||||||
2. Items inside of a list should be presented in a consistent format. For example, if your items present decorative icons, the icons should be positioned in the same way between items. | ||||||
3. Items should never render [nested interactives](https://dequeuniversity.com/rules/axe/4.4/nested-interactive). Screen readers are unable to select the correct interactive element when nested interactives are used. For example, avoid placing a button inside of an `ion-item` that has `button="true"`. | ||||||
4. Use [content types](#content-types) correctly. The Item component is designed to be a row in a [List](./list) and should not be used as a general purpose container. | ||||||
|
||||||
## Properties | ||||||
<Props /> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
.best-practice__do_dont { | ||
display: grid; | ||
|
||
grid-template-columns: 1fr 1fr; | ||
|
||
gap: 12px; | ||
} | ||
|
||
/* Collapse to 1 column per row on smaller viewports */ | ||
@media (max-width: 996px) { | ||
.best-practice__do_dont { | ||
grid-template-columns: 1fr; | ||
} | ||
} | ||
|
||
.best-practice__container figcaption { | ||
text-align: start; | ||
} | ||
|
||
.best-practice__do p, | ||
.best-practice__dont p, | ||
.best-practice__caution p { | ||
padding: 8px 16px; | ||
} | ||
|
||
.best-practice__image-wrapper { | ||
border-radius: 8px 8px 0px 0px; | ||
|
||
overflow: hidden; | ||
} | ||
|
||
.best-practice__dont-text, | ||
.best-practice__do-text, | ||
.best-practice__caution-text { | ||
padding: 12px 16px; | ||
|
||
font-weight: 600; | ||
|
||
border-radius: 0px 0px 8px 8px; | ||
} | ||
|
||
.best-practice__do .best-practice__image-wrapper { | ||
border: 1px solid var(--c-blue-10); | ||
} | ||
|
||
.best-practice__dont .best-practice__image-wrapper { | ||
border: 1px solid var(--c-red-10); | ||
} | ||
|
||
.best-practice__caution .best-practice__image-wrapper { | ||
border: 1px solid var(--c-yellow-10); | ||
} | ||
|
||
.best-practice__dont-text { | ||
color: var(--c-red-100); | ||
background: var(--c-red-10); | ||
} | ||
.best-practice__do-text { | ||
color: var(--c-blue-100); | ||
background: var(--c-blue-10); | ||
} | ||
|
||
.best-practice__caution-text { | ||
/* --c-yellow-100 does not have enough contrast | ||
* placed on top of --c-yellow-10, so we manually | ||
* choose a darker text color here. | ||
*/ | ||
color: #7e5e17; | ||
background: var(--c-yellow-10); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import './best-practice-figure.css'; | ||
|
||
export default function BestPracticeFigure({ text, doText, dontText, cautionText, doImage, dontImage, cautionImage }) { | ||
return ( | ||
<div className="best-practice__container"> | ||
<p>{text}</p> | ||
<div className="best-practice__do_dont"> | ||
<figure className="best-practice__do"> | ||
<div className="best-practice__image-wrapper">{doImage}</div> | ||
<figcaption> | ||
<div className="best-practice__do-text">Do</div> | ||
<p>{doText}</p> | ||
</figcaption> | ||
</figure> | ||
{dontText && dontImage && ( | ||
<figure className="best-practice__dont"> | ||
<div className="best-practice__image-wrapper">{dontImage}</div> | ||
<figcaption> | ||
<div className="best-practice__dont-text">Don't</div> | ||
<p>{dontText}</p> | ||
</figcaption> | ||
</figure> | ||
)} | ||
{cautionText && cautionImage && ( | ||
<figure className="best-practice__caution"> | ||
<div className="best-practice__image-wrapper">{cautionImage}</div> | ||
<figcaption> | ||
<div className="best-practice__caution-text">Caution</div> | ||
<p>{cautionText}</p> | ||
</figcaption> | ||
</figure> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
liamdebeasi marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could take this without the cursor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept the cursor because I wanted to show that the information icon only shows up when the input is focused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. Can we have the cursor at the end of the word then without a space? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do that. Though I'm curious... why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just looks weird to me with the space hah |
brandyscarney marked this conversation as resolved.
Show resolved
Hide resolved
|
brandyscarney marked this conversation as resolved.
Show resolved
Hide resolved
|
liamdebeasi marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.