Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 27 additions & 1 deletion docs/api/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,41 @@ import Types from '@site/static/usage/v7/input/types/index.md';

<Types />

## Labels

## Label Placement
Input has several options for supplying a label for the component:
Comment thread
liamdebeasi marked this conversation as resolved.
Outdated

- `label` property: used for plaintext labels
- `label` slot: used for custom HTML labels (experimental)
- `aria-label`: used for selects with no visible label
Comment thread
liamdebeasi marked this conversation as resolved.
Outdated

### Label Placement

Labels will take up the width of their content by default. Developers can use the `labelPlacement` property to control how the label is placed relative to the control.

import LabelPlacement from '@site/static/usage/v7/input/label-placement/index.md';

<LabelPlacement />

### Label Slot (experimental)

While plaintext labels should be passed in via the `label` property, if custom HTML is needed, it can be passed through the `label` slot instead.

Note that this feature is considered experimental because it relies on a simulated version of [Web Component slots](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots). As a result, the simulated behavior may not exactly match the native slot behavior.

import LabelSlot from '@site/static/usage/v7/input/label-slot/index.md';

<LabelSlot />

### No Visible Label

If no visible label is needed, devs should still supply an `aria-label` so the input is accessible to screen readers.
Comment thread
liamdebeasi marked this conversation as resolved.
Outdated

import NoVisibleLabel from '@site/static/usage/v7/input/no-visible-label/index.md';

<NoVisibleLabel />



## Clear Options

Expand Down
9 changes: 9 additions & 0 deletions static/usage/v7/input/label-slot/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```html
<ion-list>
<ion-item>
<ion-input labelPlacement="floating" value="hi@ionic.io">
<div slot="label">Email <ion-text color="danger">(Required)</ion-text></div>
</ion-input>
</ion-item>
</ion-list>
```
28 changes: 28 additions & 0 deletions static/usage/v7/input/label-slot/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>input</title>
<link rel="stylesheet" href="../../../common.css" />
<script src="../../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7.0.11-dev.11686769094.1eb95367/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7.0.11-dev.11686769094.1eb95367/css/ionic.bundle.css" />
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-list>
<ion-item>
<ion-input label-placement="floating" value="hi@ionic.io">
<div slot="label">Email <ion-text color="danger">(Required)</ion-text></div>
</ion-input>
</ion-item>
</ion-list>
</div>
</ion-content>
</ion-app>
</body>
</html>
12 changes: 12 additions & 0 deletions static/usage/v7/input/label-slot/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
version="7"
code={{ javascript, react, vue, angular }}
src="usage/v7/input/label-slot/demo.html"
/>
9 changes: 9 additions & 0 deletions static/usage/v7/input/label-slot/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```html
<ion-list>
<ion-item>
<ion-input label-placement="floating" value="hi@ionic.io">
<div slot="label">Email <ion-text color="danger">(Required)</ion-text></div>
</ion-input>
</ion-item>
</ion-list>
```
17 changes: 17 additions & 0 deletions static/usage/v7/input/label-slot/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```tsx
import React from 'react';
import { IonInput, IonItem, IonList, IonText } from '@ionic/react';

function Example() {
return (
<IonList>
<IonItem>
<IonInput labelPlacement="floating" value="hi@ionic.io">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The label is not floating in the StackBlitz example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The StackBlitz examples are using the latest version of Ionic which does not have the slotted label feature. As a result, passing a label to the input will not work as expected. If you manually install the dev build (7.0.11-dev.11686769094.1eb95367) it should work as expected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh weird that it works for the other frameworks though

<div slot="label">Email <IonText color="danger">(Required)</IonText></div>
</IonInput>
</IonItem>
</IonList>
);
}
export default Example;
```
20 changes: 20 additions & 0 deletions static/usage/v7/input/label-slot/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```html
<template>
<ion-list>
<ion-item>
<ion-input label-placement="floating" value="hi@ionic.io">
<div slot="label">Email <ion-text color="danger">(Required)</ion-text></div>
</ion-input>
</ion-item>
</ion-list>
</template>

<script lang="ts">
import { IonInput, IonItem, IonList, IonText } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: { IonInput, IonItem, IonList, IonText },
});
</script>
```
7 changes: 7 additions & 0 deletions static/usage/v7/input/no-visible-label/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```html
<ion-list>
<ion-item>
<ion-input aria-label="Email" value="hi@ionic.io"></ion-input>
</ion-item>
</ion-list>
```
26 changes: 26 additions & 0 deletions static/usage/v7/input/no-visible-label/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>input</title>
<link rel="stylesheet" href="../../../common.css" />
<script src="../../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" />
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-list>
<ion-item>
<ion-input aria-label="Email" value="hi@ionic.io"></ion-input>
</ion-item>
</ion-list>
</div>
</ion-content>
</ion-app>
</body>
</html>
12 changes: 12 additions & 0 deletions static/usage/v7/input/no-visible-label/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
version="7"
code={{ javascript, react, vue, angular }}
src="usage/v7/input/no-visible-label/demo.html"
/>
7 changes: 7 additions & 0 deletions static/usage/v7/input/no-visible-label/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```html
<ion-list>
<ion-item>
<ion-input aria-label="Email" value="hi@ionic.io"></ion-input>
</ion-item>
</ion-list>
```
15 changes: 15 additions & 0 deletions static/usage/v7/input/no-visible-label/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```tsx
import React from 'react';
import { IonInput, IonItem, IonList } from '@ionic/react';

function Example() {
return (
<IonList>
<IonItem>
<IonInput aria-label="Email" value="hi@ionic.io"></IonInput>
</IonItem>
</IonList>
);
}
export default Example;
```
18 changes: 18 additions & 0 deletions static/usage/v7/input/no-visible-label/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```html
<template>
<ion-list>
<ion-item>
<ion-input aria-label="Email" value="hi@ionic.io"></ion-input>
</ion-item>
</ion-list>
</template>

<script lang="ts">
import { IonInput, IonItem, IonList } from '@ionic/vue';
import { defineComponent } from 'vue';

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