Skip to content

fix(form-textarea): Bug fixes and features #2111

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 67 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
095ac6e
[WIP] fix(form-textarea): Bug fixes and features
tmorehouse Oct 27, 2018
7c69b2c
Add better auto rows re-size capabilities
tmorehouse Oct 28, 2018
70f4e77
lint
tmorehouse Oct 28, 2018
edcfe2c
lint
tmorehouse Oct 28, 2018
3a37afa
Update form-textarea.js
tmorehouse Oct 28, 2018
3ed45f7
Update form-textarea.js
tmorehouse Oct 28, 2018
449d3c5
Update form-textarea.js
tmorehouse Oct 28, 2018
1e7be12
Update form-textarea.js
tmorehouse Oct 28, 2018
8284093
Update form-textarea.js
tmorehouse Oct 28, 2018
4f4d25a
Update form-textarea.js
tmorehouse Oct 28, 2018
24193f0
Update package.json
tmorehouse Oct 28, 2018
e838d33
Ajust event $emit ordering
tmorehouse Oct 28, 2018
8c1ee38
Create form-formatting mixin
tmorehouse Oct 28, 2018
ab9990a
Add stringify method for mixin
tmorehouse Oct 28, 2018
2cbbade
Update package.json
tmorehouse Oct 28, 2018
b04338f
Update and rename form-formatting.js to form-text,js
tmorehouse Oct 28, 2018
70f72e9
Add in formatter features
tmorehouse Oct 28, 2018
e738035
Rename form-text,js to form-text.js
tmorehouse Oct 28, 2018
b74da4e
Update form-text.js
tmorehouse Oct 28, 2018
5cddfba
Update README.md
tmorehouse Oct 28, 2018
550d5a0
Update form-text.js
tmorehouse Oct 28, 2018
474a394
Update README.md
tmorehouse Oct 28, 2018
6e707ac
Update README.md
tmorehouse Oct 28, 2018
585f94f
Update form-textarea.js
tmorehouse Oct 28, 2018
9a0dd3a
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
7ead478
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
c20ecfe
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
902ef7a
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
a43e3e6
Commended out auto height testing
tmorehouse Oct 28, 2018
a8f9828
Update form-textarea.js
tmorehouse Oct 28, 2018
906d9a6
add formatter tests
tmorehouse Oct 28, 2018
02229ec
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
b6a0dad
Update form-textarea.spec.js
tmorehouse Oct 28, 2018
2543e56
Update form-textarea.js
tmorehouse Oct 28, 2018
dbeaa49
keep-alive test
tmorehouse Oct 29, 2018
9612a75
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
1e68bfb
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
240d4ba
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
f538c11
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
dc69225
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
22973c1
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
e5b620d
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
29e76a6
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
eb55a92
Update form-textarea.spec.js
tmorehouse Oct 29, 2018
158467e
Delete form-textarea.html
tmorehouse Oct 29, 2018
f8174d6
Update form-textarea.js
tmorehouse Oct 29, 2018
440f787
form-text mixin: add class conditionals for b-form-input
tmorehouse Nov 2, 2018
cd5262e
Typos fix
mosinve Nov 2, 2018
6947a1b
Typos fix
mosinve Nov 2, 2018
070a9ee
deterct if IME composition in progress
tmorehouse Nov 2, 2018
0b3266a
Merge branch 'dev' into tmorehouse/b-form-textarea
tmorehouse Nov 20, 2018
a418d98
emulate .number and .trim modifiers, reorder events, lazy format on o…
tmorehouse Nov 21, 2018
a06c105
add blur listener to textarea
tmorehouse Nov 21, 2018
a52d155
Update form-text.js
tmorehouse Nov 21, 2018
11f26b0
Update form-text.js
tmorehouse Nov 21, 2018
d96d2b9
Update form-textarea.spec.js
tmorehouse Nov 21, 2018
bc7531a
Update form-textarea.spec.js
tmorehouse Nov 21, 2018
52dbdf1
tests lint
tmorehouse Nov 21, 2018
a6ffdd3
Update package.json
tmorehouse Nov 21, 2018
ddb190e
Update README.md
tmorehouse Nov 21, 2018
a68339e
Update README.md
tmorehouse Nov 21, 2018
a3e17bd
add trim and number modifier tests
tmorehouse Nov 21, 2018
77e07c6
Update README.md
tmorehouse Nov 21, 2018
6b8f052
test lint
tmorehouse Nov 21, 2018
546e0fd
Update form-textarea.spec.js
tmorehouse Nov 21, 2018
608fa5c
Update form-textarea.spec.js
tmorehouse Nov 21, 2018
3c30f3b
Update README.md
tmorehouse Nov 21, 2018
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
144 changes: 120 additions & 24 deletions src/components/form-textarea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,59 @@ export default {
<!-- form-textarea-1.vue -->
```

## Displayed rows
## Control sizing
Set text height using the `size` prop to `sm` or `lg` for small or large respectively.

`<b-form-textarea>` automaticlly adjusts its height (text rows) to fit the content,
even as the user enters text. For a textarea with no content, the number of rows
starts at `1`.
To control width, place the input inside standard Bootstrap grid column.

To set the initial minimum height (in rows), set the `rows` prop to the desired
number of lines. If no value is provided to `rows`, then it will default to `1`.
```html
<b-container fluid>
<b-row class="my-1">
<b-col sm="2"><label for="input-small">Small:</label></b-col>
<b-col sm="10">
<b-form-textarea id="input-small" size="sm" type="text" placeholder="Small Textarea"></b-form-textarea>
</b-col>
</b-row>
<b-row class="my-1">
<b-col sm="2"><label for="input-default">Default:</label></b-col>
<b-col sm="10">
<b-form-textarea id="input-default" type="text" placeholder="Default Textarea"></b-form-text-area>
</b-col>
</b-row>
<b-row class="my-1">
<b-col sm="2"><label for="input-large">Large:</label></b-col>
<b-col sm="10">
<b-form-textarea id="input-large" size="lg" type="text" placeholder="Large Textarea"></b-form-textarea>
</b-col>
</b-row>
</b-container>

<!-- form-textarea-size-1.vue -->
```

To limit the maximum rows that the text area will grow to (before showing a scrollbar),
set the `max-rows` prop to the maximum number of lines of text.

To keep the text-area at a set height, set both `rows` and `max-rows` to the same value.
## Displayed rows
To set the height of `<b-form-textarea>`, set the `rows` prop to the desired number of
rows. If no value is provided to `rows`, then it will default to `2` (the browser
default and minimum acceptable value). Setting it to null or a value below 2 will
result in the default of `2` being used.

**Note:** auto rows will only work when the user explicitly enters newlines in the textarea.
### Disable resize handle
Some web browsers will allow the user to re-size the height of the textarea.
To disable this feature, set the `no-resize` prop to `true`.

### Disable resize
### Auto height
`<b-form-textarea>` can also automatically adjust its height (text rows) to fit the content,
even as the user enters text.

Note that some web browsers will allow the user to re-size the hight of the textarea.
To disable this, set the `no-resize` prop to `true`.
To set the initial minimum height (in rows), set the `rows` prop to the desired
number of lines (or leave it at the default of `2`).

To limit the maximum rows that the text area will grow to (before showing a scrollbar),
set the `max-rows` prop to the maximum number of lines of text.

## Contextual states

## Textarea contextual states
Bootstrap includes validation styles for `valid` and `invalid` states on most form controls.

Generally speaking, you’ll want to use a particular state for specific types of feedback:
Expand All @@ -61,16 +90,16 @@ Generally speaking, you’ll want to use a particular state for specific types o
- `null` Displays no validation state

To apply one of the contextual state icons on `<b-form-textarea>`, set the `state` prop to:
- `'invalid'` or `false` to apply invalid styling)
- `'valid'` or `true` to apply valid highlighting,
- The string `'invalid'` or Boolean `false` to apply invalid styling
- The string `'valid'` or Boolean `true` to apply valid styling
- `null` for no validation contextual state

```html
<template>
<b-form-textarea id="textarea2"
state="invalid"
:state="text.length >= 10"
v-model.trim="text"
placeholder="Enter something"
placeholder="Enter at least 10 characters"
:rows="3"></b-form-textarea>
</template>

Expand All @@ -88,7 +117,6 @@ export default {
```

### Conveying contextual state to assistive technologies and colorblind users

Using these contextual states to denote the state of a form control only provides a
visual, color-based indication, which will not be conveyed to users of assistive
technologies - such as screen readers - or to colorblind users.
Expand All @@ -98,11 +126,10 @@ include a hint about state in the form control's `<label>` text itself, or by pr
an additional help text block.

### ARIA `aria-invalid` attribute

When `<b-form-textarea>` has an invalid contextual state (i.e. `'invalid'` or `false`)
you may also want to set the prop `aria-invalid` to `true`, or one of hte supported values:

- `false`: No errors detected (default)
- `false`: No errors (default)
- `true` or `'true'`: The value has failed validation.
- `'grammar'`: A grammatical error has been detected.
- `'spelling'` A spelling error has been detected.
Expand All @@ -112,11 +139,16 @@ not explicity set, `<b-form-textarea>` will automatically set the `aria-invalid`
attribute to `'true'`.


## Readonly plain text
## Formatter support
Refer to the (`<b-form-input>`)[../form-input] documentation regarding usage of the
optional formatter feature.


## Readonly plain text
If you want to have `<b-form-textarea readonly>` elements in your form styled as plain
text, set the `plaintext` prop (no need to set `readonly`) to remove the default form
field styling and preserve the correct margin and padding and height.
text, set the `plaintext` prop (no need to set `readonly` as it will be set
automatically) to remove the default form field styling and preserve the correct
text size, margin, padding and height.

```html
<template>
Expand All @@ -136,5 +168,69 @@ export default {
<!-- form-textarea-plaintext.vue -->
```

## V-model modifiers
Vue does not officially support `.lazy`, `.trim`, and `.number` modifiers on the `v-model` of
custom component based inputs, and may generate a bad user experience. Avoid using Vue's native modifiers.

To get around this, `<b-for-textarea>` and `<b-form-input>` have two boolean props `trim` and `number`
which emulate the native Vue `v-model` modifiers `.trim` and `.number` respectivley. Emulation of the
`.lazy` modifier is _not_ supported (listen for `change` or `blur` events instead).

**Notes:**
- The `number` prop takes precedence over the `trim` prop (i.e. `trim` will have no effect when `number` is set).
- When using the `number` prop, and if the value can be parsed as a number (via `parseFloat`) it will return a value of type `Number` to the `v-model`, otherwise the original input value is returned as type `String`. This is the same behaviour as the native `.number` modifier.
- The `trim` and `number` modifier props do not affect the value returned by the `input` or `change` events. These events will aways return the string value of the content of `<textarea>` after optional formatting (which may not match the value returned via the `v-model` `update` event, which handles the modifiers).


## Native and custom events
All native events (other than the custom `input` and `change` events) are supported, without
the need for the `.native` modifier.

The custom `input` and `change` events receive a single argument of the current `value` (after any
formatting has been applied), and are triggerd by user interaction.

The custom `update` event is passed the input value, and is emitted wehenever the v-model needs
updating (it is emitted before `input`, `change`. and `blur` as needed).

You can always access the native `input` and `change` events by using the `.native` modifier.


## Exposed input properties and methods
`<b-form-input>` exposes several of the native input element's properties and methods on the
component reference (i.e. assign a `ref` to your `<b-form-input ref="foo" ...>` and
use `this.$refs['foo'].propertyName` or `this.$refs['foo'].methodName(...)`).

### Input Properties

| Property | Notes
| -------- | -----
| `.selectionStart` | Read/Write
| `.selectionEnd` | Read/Write
| `.selectionDirection` | Read/Write
| `.validity` | Read only
| `.validationMessage` | Read only
| `.willValidate` | Read only

### Input Methods

| Method | Notes |
| ------ | ----- |
| `.focus()` | Focus the input |
| `.blur()` | Remove focus from the input |
| `.select()` | Selects all text within the input |
| `.setSelectionRange()` | |
| `.setRangeText()` | |
| `.setCustomValidity()` | |
| `.checkValidity()` | |
| `.reportValidity()` | |

Refer to https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement for
more information on these methods and properties. Support will vary based on
input type.


## Component alias
You can use `<b-form-textarea>` by it's shorter alias `<b-textarea>`.


<!-- Component reference added automatically from component package.json -->
22 changes: 0 additions & 22 deletions src/components/form-textarea/fixtures/form-textarea.html

This file was deleted.

Loading