@gitlab/ui 80.20.1 → 81.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/components/base/form/form_character_count/form_character_count.js +107 -0
- package/dist/components/base/form/form_textarea/form_textarea.js +11 -37
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/components/base/form/form_character_count/form_character_count.md +53 -0
- package/src/components/base/form/form_character_count/form_character_count.vue +97 -0
- package/src/components/base/form/form_textarea/form_textarea.vue +26 -69
- package/src/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [81.0.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v80.20.1...v81.0.0) (2024-06-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add `GlFormCharacterCount` component ([c3ccb44](https://gitlab.com/gitlab-org/gitlab-ui/commit/c3ccb44479939d380707b979bee6bcbbedf22d9d))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* So you can add character count to standalone inputs
|
|
12
|
+
Also renames character count related props and slots in `GlFormTextarea`
|
|
13
|
+
|
|
1
14
|
## [80.20.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v80.20.0...v80.20.1) (2024-06-12)
|
|
2
15
|
|
|
3
16
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
2
|
+
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
3
|
+
|
|
4
|
+
var script = {
|
|
5
|
+
name: 'GlFormCharacterCount',
|
|
6
|
+
props: {
|
|
7
|
+
/**
|
|
8
|
+
* Input value
|
|
9
|
+
*/
|
|
10
|
+
value: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: false,
|
|
13
|
+
default: ''
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Character count limit for the input.
|
|
17
|
+
*/
|
|
18
|
+
limit: {
|
|
19
|
+
type: Number,
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* id attribute for the character count text. Input should have `:aria-describedby="countTextId"`
|
|
24
|
+
*/
|
|
25
|
+
countTextId: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
data() {
|
|
31
|
+
return {
|
|
32
|
+
remainingCount: this.initialRemainingCount(),
|
|
33
|
+
remainingCountSrOnly: this.initialRemainingCount()
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
computed: {
|
|
37
|
+
isOverLimit() {
|
|
38
|
+
return this.remainingCount < 0;
|
|
39
|
+
},
|
|
40
|
+
isOverLimitSrOnly() {
|
|
41
|
+
return this.remainingCountSrOnly < 0;
|
|
42
|
+
},
|
|
43
|
+
countTextClass() {
|
|
44
|
+
return this.isOverLimit ? 'gl-text-danger' : 'gl-text-subtle';
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
watch: {
|
|
48
|
+
value(newValue) {
|
|
49
|
+
this.remainingCount = this.limit - this.valueLength(newValue);
|
|
50
|
+
this.debouncedUpdateRemainingCountSrOnly(newValue);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
created() {
|
|
54
|
+
// Debounce updating the remaining character count for a second so
|
|
55
|
+
// screen readers announce the remaining text after the text in the textarea.
|
|
56
|
+
this.debouncedUpdateRemainingCountSrOnly = debounce(this.updateRemainingCountSrOnly, 1000);
|
|
57
|
+
},
|
|
58
|
+
methods: {
|
|
59
|
+
valueLength(value) {
|
|
60
|
+
return (value === null || value === void 0 ? void 0 : value.length) || 0;
|
|
61
|
+
},
|
|
62
|
+
updateRemainingCountSrOnly(newValue) {
|
|
63
|
+
this.remainingCountSrOnly = this.limit - this.valueLength(newValue);
|
|
64
|
+
},
|
|
65
|
+
initialRemainingCount() {
|
|
66
|
+
return this.limit - this.valueLength(this.value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/* script */
|
|
72
|
+
const __vue_script__ = script;
|
|
73
|
+
|
|
74
|
+
/* template */
|
|
75
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('small',{class:['form-text', _vm.countTextClass],attrs:{"aria-hidden":"true"}},[(_vm.isOverLimit)?_vm._t("over-limit-text",null,{"count":Math.abs(_vm.remainingCount)}):_vm._t("remaining-count-text",null,{"count":_vm.remainingCount})],2),_vm._v(" "),_c('div',{staticClass:"gl-sr-only",attrs:{"id":_vm.countTextId,"aria-live":"polite","data-testid":"count-text-sr-only"}},[(_vm.isOverLimitSrOnly)?_vm._t("over-limit-text",null,{"count":Math.abs(_vm.remainingCountSrOnly)}):_vm._t("remaining-count-text",null,{"count":_vm.remainingCountSrOnly})],2)])};
|
|
76
|
+
var __vue_staticRenderFns__ = [];
|
|
77
|
+
|
|
78
|
+
/* style */
|
|
79
|
+
const __vue_inject_styles__ = undefined;
|
|
80
|
+
/* scoped */
|
|
81
|
+
const __vue_scope_id__ = undefined;
|
|
82
|
+
/* module identifier */
|
|
83
|
+
const __vue_module_identifier__ = undefined;
|
|
84
|
+
/* functional template */
|
|
85
|
+
const __vue_is_functional_template__ = false;
|
|
86
|
+
/* style inject */
|
|
87
|
+
|
|
88
|
+
/* style inject SSR */
|
|
89
|
+
|
|
90
|
+
/* style inject shadow dom */
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const __vue_component__ = __vue_normalize__(
|
|
95
|
+
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
96
|
+
__vue_inject_styles__,
|
|
97
|
+
__vue_script__,
|
|
98
|
+
__vue_scope_id__,
|
|
99
|
+
__vue_is_functional_template__,
|
|
100
|
+
__vue_module_identifier__,
|
|
101
|
+
false,
|
|
102
|
+
undefined,
|
|
103
|
+
undefined,
|
|
104
|
+
undefined
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
export default __vue_component__;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BFormTextarea } from 'bootstrap-vue/esm/index.js';
|
|
2
|
-
import debounce from 'lodash/debounce';
|
|
3
2
|
import uniqueId from 'lodash/uniqueId';
|
|
3
|
+
import GlFormCharacterCount from '../form_character_count/form_character_count';
|
|
4
4
|
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
5
5
|
|
|
6
6
|
const model = {
|
|
@@ -10,7 +10,8 @@ const model = {
|
|
|
10
10
|
var script = {
|
|
11
11
|
name: 'GlFormTextarea',
|
|
12
12
|
components: {
|
|
13
|
-
BFormTextarea
|
|
13
|
+
BFormTextarea,
|
|
14
|
+
GlFormCharacterCount
|
|
14
15
|
},
|
|
15
16
|
inheritAttrs: false,
|
|
16
17
|
model,
|
|
@@ -35,7 +36,7 @@ var script = {
|
|
|
35
36
|
/**
|
|
36
37
|
* Max character count for the textarea.
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
characterCountLimit: {
|
|
39
40
|
type: Number,
|
|
40
41
|
required: false,
|
|
41
42
|
default: null
|
|
@@ -48,9 +49,7 @@ var script = {
|
|
|
48
49
|
},
|
|
49
50
|
data() {
|
|
50
51
|
return {
|
|
51
|
-
|
|
52
|
-
remainingCharacterCount: this.initialRemainingCharacterCount(),
|
|
53
|
-
remainingCharacterCountSrOnly: this.initialRemainingCharacterCount()
|
|
52
|
+
characterCountTextId: uniqueId('form-textarea-character-count-')
|
|
54
53
|
};
|
|
55
54
|
},
|
|
56
55
|
computed: {
|
|
@@ -85,14 +84,8 @@ var script = {
|
|
|
85
84
|
keypressEvent() {
|
|
86
85
|
return this.submitOnEnter ? 'keyup' : null;
|
|
87
86
|
},
|
|
88
|
-
isCharacterCountOverLimit() {
|
|
89
|
-
return this.remainingCharacterCount < 0;
|
|
90
|
-
},
|
|
91
|
-
characterCountTextClass() {
|
|
92
|
-
return this.isCharacterCountOverLimit ? 'gl-text-danger' : 'gl-text-subtle';
|
|
93
|
-
},
|
|
94
87
|
showCharacterCount() {
|
|
95
|
-
return this.
|
|
88
|
+
return this.characterCountLimit !== null;
|
|
96
89
|
},
|
|
97
90
|
bFormTextareaProps() {
|
|
98
91
|
return {
|
|
@@ -104,34 +97,11 @@ var script = {
|
|
|
104
97
|
};
|
|
105
98
|
}
|
|
106
99
|
},
|
|
107
|
-
watch: {
|
|
108
|
-
value(newValue) {
|
|
109
|
-
if (!this.showCharacterCount) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.remainingCharacterCount = this.characterCount - this.valueLength(newValue);
|
|
113
|
-
this.debouncedUpdateRemainingCharacterCountSrOnly(newValue);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
created() {
|
|
117
|
-
// Debounce updating the remaining character count for a second so
|
|
118
|
-
// screen readers announce the remaining text after the text in the textarea.
|
|
119
|
-
this.debouncedUpdateRemainingCharacterCountSrOnly = debounce(this.updateRemainingCharacterCountSrOnly, 1000);
|
|
120
|
-
},
|
|
121
100
|
methods: {
|
|
122
|
-
valueLength(value) {
|
|
123
|
-
return (value === null || value === void 0 ? void 0 : value.length) || 0;
|
|
124
|
-
},
|
|
125
101
|
handleKeyPress(e) {
|
|
126
102
|
if (e.keyCode === 13 && (e.metaKey || e.ctrlKey)) {
|
|
127
103
|
this.$emit('submit');
|
|
128
104
|
}
|
|
129
|
-
},
|
|
130
|
-
updateRemainingCharacterCountSrOnly(newValue) {
|
|
131
|
-
this.remainingCharacterCountSrOnly = this.characterCount - this.valueLength(newValue);
|
|
132
|
-
},
|
|
133
|
-
initialRemainingCharacterCount() {
|
|
134
|
-
return this.characterCount - this.valueLength(this.value);
|
|
135
105
|
}
|
|
136
106
|
}
|
|
137
107
|
};
|
|
@@ -140,7 +110,11 @@ var script = {
|
|
|
140
110
|
const __vue_script__ = script;
|
|
141
111
|
|
|
142
112
|
/* template */
|
|
143
|
-
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return (_vm.showCharacterCount)?_c('div',[_c('b-form-textarea',_vm._g(_vm._b({attrs:{"aria-describedby":_vm.
|
|
113
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return (_vm.showCharacterCount)?_c('div',[_c('b-form-textarea',_vm._g(_vm._b({attrs:{"aria-describedby":_vm.characterCountTextId},nativeOn:_vm._d({},[_vm.keypressEvent,function($event){return _vm.handleKeyPress.apply(null, arguments)}])},'b-form-textarea',_vm.bFormTextareaProps,false),_vm.listeners)),_vm._v(" "),_c('gl-form-character-count',{attrs:{"value":_vm.value,"limit":_vm.characterCountLimit,"count-text-id":_vm.characterCountTextId},scopedSlots:_vm._u([{key:"over-limit-text",fn:function(ref){
|
|
114
|
+
var count = ref.count;
|
|
115
|
+
return [_vm._t("character-count-over-limit-text",null,{"count":count})]}},{key:"remaining-count-text",fn:function(ref){
|
|
116
|
+
var count = ref.count;
|
|
117
|
+
return [_vm._t("remaining-character-count-text",null,{"count":count})]}}],null,true)})],1):_c('b-form-textarea',_vm._g(_vm._b({nativeOn:_vm._d({},[_vm.keypressEvent,function($event){return _vm.handleKeyPress.apply(null, arguments)}])},'b-form-textarea',_vm.bFormTextareaProps,false),_vm.listeners))};
|
|
144
118
|
var __vue_staticRenderFns__ = [];
|
|
145
119
|
|
|
146
120
|
/* style */
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export { default as GlToast } from './components/base/toast/toast';
|
|
|
29
29
|
export { default as GlDashboardSkeleton } from './components/regions/dashboard_skeleton/dashboard_skeleton';
|
|
30
30
|
export { default as GlEmptyState } from './components/regions/empty_state/empty_state';
|
|
31
31
|
export { default as GlForm } from './components/base/form/form';
|
|
32
|
+
export { default as GlFormCharacterCount } from './components/base/form/form_character_count/form_character_count';
|
|
32
33
|
export { default as GlFormInput } from './components/base/form/form_input/form_input';
|
|
33
34
|
export { default as GlFormInputGroup } from './components/base/form/form_input_group/form_input_group';
|
|
34
35
|
export { default as GlFormRadio } from './components/base/form/form_radio/form_radio';
|
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
## Usage
|
|
2
|
+
|
|
3
|
+
`GlFormCharacterCount` can be used to add a character count to an input.
|
|
4
|
+
If you are using `GlFormTextarea` on its own see [with character count example](https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/base-form-form-textarea--with-character-count).
|
|
5
|
+
If you are wrapping your input, such as in a markdown component, and need the character
|
|
6
|
+
count separate from the input, use `GlFormCharacterCount`.
|
|
7
|
+
|
|
8
|
+
## Example
|
|
9
|
+
|
|
10
|
+
```html
|
|
11
|
+
<script>
|
|
12
|
+
import { GlFormCharacterCount, GlFormInput, GlFormGroup } from '@gitlab/ui'
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
inputId: 'form-input-with-character-count',
|
|
16
|
+
countTextId: 'character-count-text',
|
|
17
|
+
limit: 100,
|
|
18
|
+
components: { GlFormCharacterCount, GlFormInput, GlFormGroup },
|
|
19
|
+
data() {
|
|
20
|
+
return {
|
|
21
|
+
value: '',
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
methods: {
|
|
25
|
+
remainingCountText(count) {
|
|
26
|
+
return n__('%d character remaining', '%d characters remaining', count)
|
|
27
|
+
},
|
|
28
|
+
overLimitText(count) {
|
|
29
|
+
return n__('%d character over limit', '%d characters over limit', count);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
<script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<gl-form-group label="Form input with character count" :label-for="$options.inputId">
|
|
37
|
+
<gl-form-input
|
|
38
|
+
v-model="value"
|
|
39
|
+
:id="$options.inputId"
|
|
40
|
+
:value="value"
|
|
41
|
+
:aria-describedby="$options.countTextId"
|
|
42
|
+
/>
|
|
43
|
+
<gl-form-character-count
|
|
44
|
+
:value="value"
|
|
45
|
+
:limit="$options.limit"
|
|
46
|
+
:count-text-id="$options.countTextId"
|
|
47
|
+
>
|
|
48
|
+
<template #remaining-count-text="{ count }">{{ remainingCountText(count) }}</template>
|
|
49
|
+
<template #over-limit-text="{ count }">{{ overLimitText(count) }}</template>
|
|
50
|
+
</gl-form-character-count>
|
|
51
|
+
</gl-form-group>
|
|
52
|
+
<template>
|
|
53
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import debounce from 'lodash/debounce';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: 'GlFormCharacterCount',
|
|
6
|
+
props: {
|
|
7
|
+
/**
|
|
8
|
+
* Input value
|
|
9
|
+
*/
|
|
10
|
+
value: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: false,
|
|
13
|
+
default: '',
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Character count limit for the input.
|
|
17
|
+
*/
|
|
18
|
+
limit: {
|
|
19
|
+
type: Number,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* id attribute for the character count text. Input should have `:aria-describedby="countTextId"`
|
|
24
|
+
*/
|
|
25
|
+
countTextId: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
data() {
|
|
31
|
+
return {
|
|
32
|
+
remainingCount: this.initialRemainingCount(),
|
|
33
|
+
remainingCountSrOnly: this.initialRemainingCount(),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
computed: {
|
|
37
|
+
isOverLimit() {
|
|
38
|
+
return this.remainingCount < 0;
|
|
39
|
+
},
|
|
40
|
+
isOverLimitSrOnly() {
|
|
41
|
+
return this.remainingCountSrOnly < 0;
|
|
42
|
+
},
|
|
43
|
+
countTextClass() {
|
|
44
|
+
return this.isOverLimit ? 'gl-text-danger' : 'gl-text-subtle';
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
watch: {
|
|
48
|
+
value(newValue) {
|
|
49
|
+
this.remainingCount = this.limit - this.valueLength(newValue);
|
|
50
|
+
this.debouncedUpdateRemainingCountSrOnly(newValue);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
created() {
|
|
54
|
+
// Debounce updating the remaining character count for a second so
|
|
55
|
+
// screen readers announce the remaining text after the text in the textarea.
|
|
56
|
+
this.debouncedUpdateRemainingCountSrOnly = debounce(this.updateRemainingCountSrOnly, 1000);
|
|
57
|
+
},
|
|
58
|
+
methods: {
|
|
59
|
+
valueLength(value) {
|
|
60
|
+
return value?.length || 0;
|
|
61
|
+
},
|
|
62
|
+
updateRemainingCountSrOnly(newValue) {
|
|
63
|
+
this.remainingCountSrOnly = this.limit - this.valueLength(newValue);
|
|
64
|
+
},
|
|
65
|
+
initialRemainingCount() {
|
|
66
|
+
return this.limit - this.valueLength(this.value);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<div>
|
|
74
|
+
<small :class="['form-text', countTextClass]" aria-hidden="true">
|
|
75
|
+
<!--
|
|
76
|
+
@slot Internationalized over limit text. Example: `<template #over-limit-text="{ count }">{{ n__('%d character over limit', '%d characters over limit', count) }}</template>`
|
|
77
|
+
@binding {number} count
|
|
78
|
+
-->
|
|
79
|
+
<slot v-if="isOverLimit" name="over-limit-text" :count="Math.abs(remainingCount)"></slot>
|
|
80
|
+
<!--
|
|
81
|
+
@slot Internationalized character count text. Example: `<template #remaining-count-text="{ count }">{{ n__('%d character remaining', '%d characters remaining', count) }}</template>`
|
|
82
|
+
@binding {number} count
|
|
83
|
+
-->
|
|
84
|
+
|
|
85
|
+
<slot v-else name="remaining-count-text" :count="remainingCount"></slot>
|
|
86
|
+
</small>
|
|
87
|
+
<div :id="countTextId" class="gl-sr-only" aria-live="polite" data-testid="count-text-sr-only">
|
|
88
|
+
<slot
|
|
89
|
+
v-if="isOverLimitSrOnly"
|
|
90
|
+
name="over-limit-text"
|
|
91
|
+
:count="Math.abs(remainingCountSrOnly)"
|
|
92
|
+
></slot>
|
|
93
|
+
|
|
94
|
+
<slot v-else name="remaining-count-text" :count="remainingCountSrOnly"></slot>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { BFormTextarea } from 'bootstrap-vue';
|
|
3
|
-
import debounce from 'lodash/debounce';
|
|
4
3
|
import uniqueId from 'lodash/uniqueId';
|
|
4
|
+
import GlFormCharacterCount from '../form_character_count/form_character_count.vue';
|
|
5
5
|
|
|
6
6
|
const model = {
|
|
7
7
|
prop: 'value',
|
|
@@ -12,6 +12,7 @@ export default {
|
|
|
12
12
|
name: 'GlFormTextarea',
|
|
13
13
|
components: {
|
|
14
14
|
BFormTextarea,
|
|
15
|
+
GlFormCharacterCount,
|
|
15
16
|
},
|
|
16
17
|
inheritAttrs: false,
|
|
17
18
|
model,
|
|
@@ -36,7 +37,7 @@ export default {
|
|
|
36
37
|
/**
|
|
37
38
|
* Max character count for the textarea.
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
characterCountLimit: {
|
|
40
41
|
type: Number,
|
|
41
42
|
required: false,
|
|
42
43
|
default: null,
|
|
@@ -49,9 +50,7 @@ export default {
|
|
|
49
50
|
},
|
|
50
51
|
data() {
|
|
51
52
|
return {
|
|
52
|
-
|
|
53
|
-
remainingCharacterCount: this.initialRemainingCharacterCount(),
|
|
54
|
-
remainingCharacterCountSrOnly: this.initialRemainingCharacterCount(),
|
|
53
|
+
characterCountTextId: uniqueId('form-textarea-character-count-'),
|
|
55
54
|
};
|
|
56
55
|
},
|
|
57
56
|
computed: {
|
|
@@ -79,14 +78,8 @@ export default {
|
|
|
79
78
|
keypressEvent() {
|
|
80
79
|
return this.submitOnEnter ? 'keyup' : null;
|
|
81
80
|
},
|
|
82
|
-
isCharacterCountOverLimit() {
|
|
83
|
-
return this.remainingCharacterCount < 0;
|
|
84
|
-
},
|
|
85
|
-
characterCountTextClass() {
|
|
86
|
-
return this.isCharacterCountOverLimit ? 'gl-text-danger' : 'gl-text-subtle';
|
|
87
|
-
},
|
|
88
81
|
showCharacterCount() {
|
|
89
|
-
return this.
|
|
82
|
+
return this.characterCountLimit !== null;
|
|
90
83
|
},
|
|
91
84
|
bFormTextareaProps() {
|
|
92
85
|
return {
|
|
@@ -98,39 +91,12 @@ export default {
|
|
|
98
91
|
};
|
|
99
92
|
},
|
|
100
93
|
},
|
|
101
|
-
watch: {
|
|
102
|
-
value(newValue) {
|
|
103
|
-
if (!this.showCharacterCount) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.remainingCharacterCount = this.characterCount - this.valueLength(newValue);
|
|
108
|
-
this.debouncedUpdateRemainingCharacterCountSrOnly(newValue);
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
created() {
|
|
112
|
-
// Debounce updating the remaining character count for a second so
|
|
113
|
-
// screen readers announce the remaining text after the text in the textarea.
|
|
114
|
-
this.debouncedUpdateRemainingCharacterCountSrOnly = debounce(
|
|
115
|
-
this.updateRemainingCharacterCountSrOnly,
|
|
116
|
-
1000
|
|
117
|
-
);
|
|
118
|
-
},
|
|
119
94
|
methods: {
|
|
120
|
-
valueLength(value) {
|
|
121
|
-
return value?.length || 0;
|
|
122
|
-
},
|
|
123
95
|
handleKeyPress(e) {
|
|
124
96
|
if (e.keyCode === 13 && (e.metaKey || e.ctrlKey)) {
|
|
125
97
|
this.$emit('submit');
|
|
126
98
|
}
|
|
127
99
|
},
|
|
128
|
-
updateRemainingCharacterCountSrOnly(newValue) {
|
|
129
|
-
this.remainingCharacterCountSrOnly = this.characterCount - this.valueLength(newValue);
|
|
130
|
-
},
|
|
131
|
-
initialRemainingCharacterCount() {
|
|
132
|
-
return this.characterCount - this.valueLength(this.value);
|
|
133
|
-
},
|
|
134
100
|
},
|
|
135
101
|
};
|
|
136
102
|
</script>
|
|
@@ -138,42 +104,33 @@ export default {
|
|
|
138
104
|
<template>
|
|
139
105
|
<div v-if="showCharacterCount">
|
|
140
106
|
<b-form-textarea
|
|
141
|
-
:aria-describedby="
|
|
107
|
+
:aria-describedby="characterCountTextId"
|
|
142
108
|
v-bind="bFormTextareaProps"
|
|
143
109
|
v-on="listeners"
|
|
144
110
|
@[keypressEvent].native="handleKeyPress"
|
|
145
111
|
/>
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
-->
|
|
151
|
-
<slot
|
|
152
|
-
v-if="isCharacterCountOverLimit"
|
|
153
|
-
name="character-count-over-limit-text"
|
|
154
|
-
:count="Math.abs(remainingCharacterCount)"
|
|
155
|
-
></slot>
|
|
156
|
-
<!--
|
|
157
|
-
@slot Internationalized character count text. Example: `<template #character-count-text="{ count }">{{ n__('%d character remaining', '%d characters remaining', count) }}</template>`
|
|
158
|
-
@binding {number} count
|
|
159
|
-
-->
|
|
160
|
-
|
|
161
|
-
<slot v-else name="character-count-text" :count="remainingCharacterCount"></slot>
|
|
162
|
-
</small>
|
|
163
|
-
<div
|
|
164
|
-
:id="characterCountId"
|
|
165
|
-
class="gl-sr-only"
|
|
166
|
-
aria-live="polite"
|
|
167
|
-
data-testid="character-count-text-sr-only"
|
|
112
|
+
<gl-form-character-count
|
|
113
|
+
:value="value"
|
|
114
|
+
:limit="characterCountLimit"
|
|
115
|
+
:count-text-id="characterCountTextId"
|
|
168
116
|
>
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
117
|
+
<template #over-limit-text="{ count }">
|
|
118
|
+
<!--
|
|
119
|
+
@slot Internationalized over character count text. Example: `<template #character-count-over-limit-text="{ count }">{{ n__('%d character over limit', '%d characters over limit', count) }}</template>`
|
|
120
|
+
@binding {number} count
|
|
121
|
+
-->
|
|
122
|
+
<slot name="character-count-over-limit-text" :count="count"></slot>
|
|
123
|
+
</template>
|
|
124
|
+
|
|
125
|
+
<template #remaining-count-text="{ count }">
|
|
126
|
+
<!--
|
|
127
|
+
@slot Internationalized character count text. Example: `<template #remaining-character-count-text="{ count }">{{ n__('%d character remaining', '%d characters remaining', count) }}</template>`
|
|
128
|
+
@binding {number} count
|
|
129
|
+
-->
|
|
174
130
|
|
|
175
|
-
|
|
176
|
-
|
|
131
|
+
<slot name="remaining-character-count-text" :count="count"></slot
|
|
132
|
+
></template>
|
|
133
|
+
</gl-form-character-count>
|
|
177
134
|
</div>
|
|
178
135
|
<b-form-textarea
|
|
179
136
|
v-else
|
package/src/index.js
CHANGED
|
@@ -36,6 +36,7 @@ export { default as GlToast } from './components/base/toast/toast';
|
|
|
36
36
|
export { default as GlDashboardSkeleton } from './components/regions/dashboard_skeleton/dashboard_skeleton.vue';
|
|
37
37
|
export { default as GlEmptyState } from './components/regions/empty_state/empty_state.vue';
|
|
38
38
|
export { default as GlForm } from './components/base/form/form.vue';
|
|
39
|
+
export { default as GlFormCharacterCount } from './components/base/form/form_character_count/form_character_count.vue';
|
|
39
40
|
export { default as GlFormInput } from './components/base/form/form_input/form_input.vue';
|
|
40
41
|
export { default as GlFormInputGroup } from './components/base/form/form_input_group/form_input_group.vue';
|
|
41
42
|
export { default as GlFormRadio } from './components/base/form/form_radio/form_radio.vue';
|