Skip to content

Commit

Permalink
docs(input): notes about appropriate uses of counter (#3109)
Browse files Browse the repository at this point in the history
* docs(input): note deprecated properties

---------

Co-authored-by: Brandy Carney <[email protected]>
  • Loading branch information
mapsandapps and brandyscarney authored Sep 8, 2023
1 parent 288a265 commit bb90741
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/api/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,18 @@ import HelperError from '@site/static/usage/v7/input/helper-error/index.md';

The input counter is text that displays under an input to notify the user of how many characters have been entered out of the total that the input will accept. When adding counter, the default behavior is to format the value that gets displayed as `inputLength` / `maxLength`. This behavior can be customized by passing in a formatter function to the `counterFormatter` property.

The `counter` and `counterFormatter` properties on `ion-item` were [deprecated in Ionic 7](/docs/api/input#using-the-modern-syntax) and should be used directly on `ion-input` instead.

import Counter from '@site/static/usage/v7/input/counter/index.md';

<Counter />

Inputs with a counter add a border between the input and the counter, therefore they should not be placed inside of an `ion-item` which adds an additional border under the item. The `ion-padding-start` class can be added to align the counter inputs with inputs inside of items.

import CounterAlignment from '@site/static/usage/v7/input/counter-alignment/index.md';

<CounterAlignment />

## Filtering User Input

Developers can use the `ionInput` event to update the input value in response to user input such as a keypress. This is useful for filtering out invalid or unwanted characters.
Expand Down
11 changes: 11 additions & 0 deletions static/usage/v7/input/counter-alignment/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```html
<ion-list>
<ion-item>
<ion-input label="Text input" placeholder="Enter text"></ion-input>
</ion-item>

<div class="ion-padding-start">
<ion-input label="Counter input" [counter]="true" maxlength="20"></ion-input>
</div>
</ion-list>
```
30 changes: 30 additions & 0 deletions static/usage/v7/input/counter-alignment/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!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 label="Text input" placeholder="Enter text"></ion-input>
</ion-item>

<div class="ion-padding-start">
<ion-input label="Counter input" counter="true" maxlength="20"></ion-input>
</div>
</ion-list>
</div>
</ion-content>
</ion-app>
</body>
</html>
17 changes: 17 additions & 0 deletions static/usage/v7/input/counter-alignment/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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/counter-alignment/demo.html"
/>
11 changes: 11 additions & 0 deletions static/usage/v7/input/counter-alignment/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```html
<ion-list>
<ion-item>
<ion-input label="Text input" placeholder="Enter text"></ion-input>
</ion-item>

<div class="ion-padding-start">
<ion-input label="Counter input" counter="true" maxlength="20"></ion-input>
</div>
</ion-list>
```
21 changes: 21 additions & 0 deletions static/usage/v7/input/counter-alignment/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```tsx
import React from 'react';
import { IonInput, IonItem, IonList } from '@ionic/react';

function Example() {
return (
<>
<IonList>
<IonItem>
<IonInput label="Text input" placeholder="Enter text"></IonInput>
</IonItem>

<div className="ion-padding-start">
<IonInput label="Counter input" counter={true} maxlength={20}></IonInput>
</div>
</IonList>
</>
);
}
export default Example;
```
17 changes: 17 additions & 0 deletions static/usage/v7/input/counter-alignment/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```html
<template>
<ion-list>
<ion-item>
<ion-input label="Text input" placeholder="Enter text"></ion-input>
</ion-item>

<div class="ion-padding-start">
<ion-input label="Counter input" :counter="true" maxlength="20"></ion-input>
</div>
</ion-list>
</template>

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

1 comment on commit bb90741

@vercel
Copy link

@vercel vercel bot commented on bb90741 Sep 8, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ionic-docs – ./

ionic-docs-ionic1.vercel.app
ionic-docs-gqykycf8t.vercel.app
ionic-docs-git-main-ionic1.vercel.app

Please sign in to comment.