@bitrise/bitkit 12.95.0 → 12.96.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "12.95.0",
4
+ "version": "12.96.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -1,4 +1,4 @@
1
- import { ClipboardEventHandler, KeyboardEventHandler, ReactNode, useId } from 'react';
1
+ import { ClipboardEventHandler, FocusEventHandler, KeyboardEventHandler, ReactNode, useId } from 'react';
2
2
  import {
3
3
  chakra,
4
4
  FormControl,
@@ -47,26 +47,30 @@ const TagsInput = ({
47
47
  onRemove(value[value.length - 1]);
48
48
  }
49
49
  };
50
+ const addValues = (maybeValues: string) => {
51
+ const newValue = maybeValues.split(separator).filter((item) => item && !item.match(/\s/) && !value.includes(item));
52
+ if (newValue.length > 0) {
53
+ onNewValues(newValue);
54
+ }
55
+ };
50
56
  const keydownHandler: KeyboardEventHandler<HTMLInputElement> = (ev) => {
51
57
  const target = ev.currentTarget;
52
58
  if (ev.key.match(separator)) {
53
59
  ev.preventDefault();
54
- if (target.value) {
55
- const newValue = target.value.split(separator)[0];
56
- if (!value.includes(newValue)) {
57
- onNewValues([newValue]);
58
- }
59
- target.value = '';
60
- }
60
+ addValues(target.value);
61
+ target.value = '';
61
62
  }
62
63
  };
63
64
  const pasteEventHandler: ClipboardEventHandler<HTMLInputElement> = (ev) => {
64
65
  ev.preventDefault();
65
- const newItems = ev.clipboardData
66
- .getData('text/plain')
67
- .split(separator)
68
- .filter((item) => item && !item.match(/\s/) && !value.includes(item));
69
- onNewValues(newItems);
66
+ addValues(ev.clipboardData.getData('text/plain'));
67
+ };
68
+ const blurHandler: FocusEventHandler<HTMLInputElement> = (ev) => {
69
+ const target = ev.currentTarget;
70
+ if (target.value) {
71
+ addValues(target.value);
72
+ target.value = '';
73
+ }
70
74
  };
71
75
  const removeItem = (deleted: string) => {
72
76
  onRemove(deleted);
@@ -135,6 +139,7 @@ const TagsInput = ({
135
139
  _focusVisible={{ boxShadow: 'none' }}
136
140
  flexGrow="1"
137
141
  id={id}
142
+ onBlur={blurHandler}
138
143
  onKeyDown={keydownHandler}
139
144
  onKeyUp={keyupHandler}
140
145
  onPaste={pasteEventHandler}