@kiva/kv-components 1.2.0 → 1.4.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 CHANGED
@@ -3,6 +3,44 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.4.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@1.3.0...@kiva/kv-components@1.4.0) (2021-12-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **KvTextInput:** focus the input after clearing text ([2093abb](https://github.com/kiva/kv-ui-elements/commit/2093abb30dca870c661f5354e043f0c40290ef81))
12
+
13
+
14
+
15
+
16
+
17
+ # [1.3.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@1.2.2...@kiva/kv-components@1.3.0) (2021-12-13)
18
+
19
+
20
+ ### Features
21
+
22
+ * **KvTextInput:** adds a button which clears the search form ([bf4166e](https://github.com/kiva/kv-ui-elements/commit/bf4166e604bfd08ab1c128eda10c51fc81c359ec))
23
+
24
+
25
+
26
+
27
+
28
+ ## [1.2.2](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@1.2.1...@kiva/kv-components@1.2.2) (2021-11-24)
29
+
30
+ **Note:** Version bump only for package @kiva/kv-components
31
+
32
+
33
+
34
+
35
+
36
+ ## [1.2.1](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@1.2.0...@kiva/kv-components@1.2.1) (2021-11-17)
37
+
38
+ **Note:** Version bump only for package @kiva/kv-components
39
+
40
+
41
+
42
+
43
+
6
44
  # [1.2.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@1.1.3...@kiva/kv-components@1.2.0) (2021-11-12)
7
45
 
8
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -46,7 +46,7 @@
46
46
  "test": "jest"
47
47
  },
48
48
  "dependencies": {
49
- "@kiva/kv-tokens": "^1.1.0",
49
+ "@kiva/kv-tokens": "^1.2.1",
50
50
  "@mdi/js": "^5.9.55",
51
51
  "aria-hidden": "^1.1.3",
52
52
  "embla-carousel": "^4.5.3",
@@ -54,5 +54,5 @@
54
54
  "vue": "^2.6.12",
55
55
  "vue-focus-lock": "^1.4.1"
56
56
  },
57
- "gitHead": "92e78ad56931517905171d6127ce39f0a4eb3d8a"
57
+ "gitHead": "bd8e32aeadb80c9767a72d5cf10c5e290d615ca7"
58
58
  }
@@ -1,4 +1,4 @@
1
- import { render } from '@testing-library/vue';
1
+ import { render, fireEvent } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import { axe, toHaveNoViolations } from 'jest-axe';
4
4
  import KvTextInput from '../../../../vue/KvTextInput.vue';
@@ -53,4 +53,22 @@ describe('KvTextInput', () => {
53
53
 
54
54
  expect(results).toHaveNoViolations();
55
55
  });
56
+
57
+ it('clear button cleans the input value', async () => {
58
+ const { getByRole } = render(KvTextInput, {
59
+ props: {
60
+ canClear: true,
61
+ valid: true,
62
+ id: 'foo',
63
+ },
64
+ });
65
+ const textInputEl = getByRole('textbox');
66
+ expect(textInputEl.value).toEqual('');
67
+ await userEvent.type(textInputEl, 'abc 123');
68
+ expect(textInputEl.value).toEqual('abc 123');
69
+ const buttonInputEl = getByRole('button');
70
+ expect(buttonInputEl).toBeDefined();
71
+ await fireEvent.click(buttonInputEl);
72
+ expect(textInputEl.value).toEqual('');
73
+ });
56
74
  });
package/vue/KvSwitch.vue CHANGED
@@ -12,7 +12,6 @@
12
12
  class="tw-sr-only tw-peer"
13
13
  type="checkbox"
14
14
  role="switch"
15
- :value="value"
16
15
  :disabled="disabled"
17
16
  v-on="inputListeners"
18
17
  @change.prevent="onChange"
@@ -28,9 +28,9 @@
28
28
  'tw-pl-6' : icon,
29
29
  }"
30
30
  :placeholder="placeholder"
31
- :value="value"
32
31
  :disabled="disabled"
33
32
  v-bind="$attrs"
33
+ :value="valueInput"
34
34
  @input="onInput"
35
35
  v-on="inputListeners"
36
36
  >
@@ -45,6 +45,17 @@
45
45
  :icon="mdiAlertCircleOutline"
46
46
  class="tw-absolute tw-top-1.5 tw-right-1.5 tw-pointer-events-none tw-text-danger"
47
47
  />
48
+ <button
49
+ v-if="canClear && valid && !!valueInput"
50
+ type="button"
51
+ class="tw-absolute tw-top-1.5 tw-right-1.5"
52
+ @click="clearInput"
53
+ >
54
+ <span class="tw-sr-only">clear input</span>
55
+ <kv-material-icon
56
+ :icon="mdiClose"
57
+ />
58
+ </button>
48
59
  <div
49
60
  v-if="$slots.error"
50
61
  class="tw-text-danger tw-text-small tw-font-medium tw-mt-1"
@@ -57,7 +68,7 @@
57
68
  </template>
58
69
 
59
70
  <script>
60
- import { mdiAlertCircleOutline } from '@mdi/js';
71
+ import { mdiAlertCircleOutline, mdiClose } from '@mdi/js';
61
72
  import KvMaterialIcon from './KvMaterialIcon.vue';
62
73
 
63
74
  /* eslint-disable max-len */
@@ -152,10 +163,19 @@ export default {
152
163
  type: String,
153
164
  default: 'text',
154
165
  },
166
+ /** canClear prop
167
+ * When set to true, adds a button positioned to the right edge of the input containing an “X”
168
+ * */
169
+ canClear: {
170
+ type: Boolean,
171
+ default: false,
172
+ },
155
173
  },
156
174
  data() {
157
175
  return {
158
176
  mdiAlertCircleOutline,
177
+ mdiClose,
178
+ valueInput: this.value,
159
179
  };
160
180
  },
161
181
  computed: {
@@ -168,6 +188,7 @@ export default {
168
188
  input: () => {},
169
189
  };
170
190
  },
191
+
171
192
  },
172
193
  methods: {
173
194
  onInput(event) {
@@ -176,6 +197,7 @@ export default {
176
197
  * @event input
177
198
  * @type {Event}
178
199
  */
200
+ this.valueInput = event.target.value;
179
201
  this.$emit('input', event.target.value);
180
202
  },
181
203
  focus() {
@@ -184,6 +206,11 @@ export default {
184
206
  blur() {
185
207
  this.$refs.textInputRef.blur();
186
208
  },
209
+ clearInput() {
210
+ this.valueInput = '';
211
+ this.$emit('input', '');
212
+ this.focus();
213
+ },
187
214
  },
188
215
  };
189
216
  </script>
@@ -19,6 +19,8 @@ export default {
19
19
  valid: true,
20
20
  icon: null,
21
21
  type: 'text',
22
+ canClear: false,
23
+ value: '',
22
24
  },
23
25
  };
24
26
 
@@ -32,6 +32,7 @@ const DefaultTemplate = (args, {
32
32
  :placeholder="placeholder"
33
33
  :valid="valid"
34
34
  :icon="icon"
35
+ :canClear="canClear"
35
36
  v-model="textInputModel"
36
37
  @input="onInput"
37
38
  style="width: 25rem;"
@@ -164,6 +165,11 @@ Icon.args = {
164
165
  icon: mdiMagnify,
165
166
  };
166
167
 
168
+ export const canClear = DefaultTemplate.bind({});
169
+ canClear.args = {
170
+ canClear: true,
171
+ };
172
+
167
173
  export const PlaceholderText = (args, {
168
174
  argTypes,
169
175
  }) => ({