Skip to content

Commit

Permalink
feat(alert): add support for textarea (#16851)
Browse files Browse the repository at this point in the history
resolves #14153
  • Loading branch information
tawfiek authored and liamdebeasi committed Nov 11, 2019
1 parent bef0f53 commit b28cf02
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 22 deletions.
2 changes: 1 addition & 1 deletion core/src/components/alert/alert-interface.ts
Expand Up @@ -20,7 +20,7 @@ export interface AlertOptions {
}

export interface AlertInput {
type?: TextFieldTypes | 'checkbox' | 'radio';
type?: TextFieldTypes | 'checkbox' | 'radio' | 'textarea';
name?: string;
placeholder?: string;
value?: any;
Expand Down
5 changes: 5 additions & 0 deletions core/src/components/alert/alert.scss
Expand Up @@ -197,3 +197,8 @@
.alert-checkbox-inner {
box-sizing: border-box;
}

textarea.alert-input {
min-height: $alert-input-min-height;
resize: none;
}
59 changes: 40 additions & 19 deletions core/src/components/alert/alert.tsx
Expand Up @@ -373,25 +373,46 @@ export class Alert implements ComponentInterface, OverlayInterface {
}
return (
<div class="alert-input-group" aria-labelledby={labelledby}>
{ inputs.map(i => (
<div class="alert-input-wrapper">
<input
placeholder={i.placeholder}
value={i.value}
type={i.type}
min={i.min}
max={i.max}
onInput={e => i.value = (e.target as any).value}
id={i.id}
disabled={i.disabled}
tabIndex={0}
class={{
'alert-input': true,
'alert-input-disabled': i.disabled || false
}}
/>
</div>
))}
{ inputs.map(i => {
if (i.type === 'textarea') {
return (
<div class="alert-input-wrapper">
<textarea
placeholder={i.placeholder}
value={i.value}
onInput={e => i.value = (e.target as any).value}
id={i.id}
disabled={i.disabled}
tabIndex={0}
class={{
'alert-input': true,
'alert-input-disabled': i.disabled || false
}}
/>
</div>
);
} else {
return (
<div class="alert-input-wrapper">
<input
placeholder={i.placeholder}
value={i.value}
type={i.type}
min={i.min}
max={i.max}
onInput={e => i.value = (e.target as any).value}
id={i.id}
disabled={i.disabled}
tabIndex={0}
class={{
'alert-input': true,
'alert-input-disabled': i.disabled || false
}}
/>
</div>
);
}
})}
</div>
);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/components/alert/alert.vars.scss
Expand Up @@ -14,3 +14,6 @@ $alert-button-line-height: 20px !default;

/// @prop - Font size of the alert button
$alert-button-font-size: 14px !default;

/// @prop - Minimum height of a textarea in the alert
$alert-input-min-height: 37px !default;
16 changes: 15 additions & 1 deletion core/src/components/alert/readme.md
Expand Up @@ -17,7 +17,7 @@ Optionally, a `role` property can be added to a button, such as `cancel`. If a `

### Inputs

Alerts can also include several different inputs whose data can be passed back to the app. Inputs can be used as a simple way to prompt users for information. Radios, checkboxes and text inputs are all accepted, but they cannot be mixed. For example, an alert could have all radio button inputs, or all checkbox inputs, but the same alert cannot mix radio and checkbox inputs. Do note however, different types of "text" inputs can be mixed, such as `url`, `email`, `text`, etc. If you require a complex form UI which doesn't fit within the guidelines of an alert then we recommend building the form within a modal instead.
Alerts can also include several different inputs whose data can be passed back to the app. Inputs can be used as a simple way to prompt users for information. Radios, checkboxes and text inputs are all accepted, but they cannot be mixed. For example, an alert could have all radio button inputs, or all checkbox inputs, but the same alert cannot mix radio and checkbox inputs. Do note however, different types of "text" inputs can be mixed, such as `url`, `email`, `text`, `textarea` etc. If you require a complex form UI which doesn't fit within the guidelines of an alert then we recommend building the form within a modal instead.


<!-- Auto Generated Below -->
Expand Down Expand Up @@ -102,6 +102,13 @@ export class AlertExample {
value: 'hello',
placeholder: 'Placeholder 2'
},
// multiline input.
{
name: 'paragraph',
id: 'paragraph',
type: 'textarea',
placeholder: 'Placeholder 3'
},
{
name: 'name3',
value: 'http://ionicframework.com',
Expand Down Expand Up @@ -346,6 +353,13 @@ function presentAlertPrompt() {
value: 'hello',
placeholder: 'Placeholder 2'
},
// multiline input.
{
name: 'paragraph',
id: 'paragraph',
type: 'textarea',
placeholder: 'Placeholder 3'
},
{
name: 'name3',
value: 'http://ionicframework.com',
Expand Down
5 changes: 5 additions & 0 deletions core/src/components/alert/test/basic/index.html
Expand Up @@ -131,6 +131,11 @@
placeholder: 'Placeholder 3',
disabled: true
},
{
type: 'textarea',
placeholder: 'Placeholder 4',
value: 'Textarea hello'
},
{
name: 'name3',
type: 'text',
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions core/src/components/alert/usage/angular.md
Expand Up @@ -73,6 +73,13 @@ export class AlertExample {
value: 'hello',
placeholder: 'Placeholder 2'
},
// multiline input.
{
name: 'paragraph',
id: 'paragraph',
type: 'textarea',
placeholder: 'Placeholder 3'
},
{
name: 'name3',
value: 'http://ionicframework.com',
Expand Down
7 changes: 7 additions & 0 deletions core/src/components/alert/usage/javascript.md
Expand Up @@ -58,6 +58,13 @@ function presentAlertPrompt() {
value: 'hello',
placeholder: 'Placeholder 2'
},
// multiline input.
{
name: 'paragraph',
id: 'paragraph',
type: 'textarea',
placeholder: 'Placeholder 3'
},
{
name: 'name3',
value: 'http://ionicframework.com',
Expand Down
1 change: 0 additions & 1 deletion core/src/interface.d.ts
Expand Up @@ -36,7 +36,6 @@ export * from './utils/overlays-interface';
export * from './global/config';
export { Gesture, GestureConfig, GestureDetail } from './utils/gesture';

// Global aux types
export type TextFieldTypes = 'date' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'url' | 'time';
export type Side = 'start' | 'end';
export type PredefinedColors = 'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'danger' | 'light' | 'medium' | 'dark';
Expand Down

0 comments on commit b28cf02

Please sign in to comment.