Skip to content

Commit a281f65

Browse files
fix: TagInput - allow spaces in tags, enable space to close tags (#5697)
* Add allowSpacesInTags attribute, enable space to close tag if not allowed * Fix styling of input to fill available space without wrapping * Use allowSpacesInTags prop * Bump version + changelog --------- Co-authored-by: Tim Arney <timarney@users.noreply.github.com>
1 parent e6ea707 commit a281f65

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

app/(gcforms)/[locale]/(form administration)/form-builder/components/shared/email-tags/EmailTags.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const EmailTags = ({
3333
}}
3434
label={t("share.emailLabel", { ns: "form-builder" })}
3535
description=""
36+
allowSpacesInTags={false}
3637
onTagAdd={(tag) => {
3738
setTags([...new Set([...tags, tag])]);
3839
}}

packages/tag-input/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.1] - 2025-06-12
9+
10+
### Added
11+
12+
- Add allowSpacesInTags prop. When false, enable space to close tags.
13+
14+
### Fixed
15+
16+
- Improved styling on tag input element
17+
818
## [1.0.0] - 2025-05-14
919

1020
### Added

packages/tag-input/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gcforms/tag-input",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"author": "Canadian Digital Service",
55
"license": "MIT",
66
"publishConfig": {

packages/tag-input/src/TagInput.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const TagInput = ({
2626
placeholder,
2727
description,
2828
restrictDuplicates = true,
29+
allowSpacesInTags = true,
2930
maxTags,
3031
onTagAdd,
3132
onTagRemove,
@@ -39,6 +40,7 @@ export const TagInput = ({
3940
placeholder?: string;
4041
description?: string;
4142
restrictDuplicates?: boolean;
43+
allowSpacesInTags?: boolean;
4244
maxTags?: number;
4345
onTagAdd?: (tag: string) => void;
4446
onTagRemove?: (tag: string) => void;
@@ -136,7 +138,12 @@ export const TagInput = ({
136138
resetMessages();
137139

138140
const { key } = event;
139-
const acceptKeys = [keys.ENTER, keys.TAB, keys.COMMA];
141+
const acceptKeys = [
142+
keys.ENTER,
143+
keys.TAB,
144+
keys.COMMA,
145+
...(allowSpacesInTags ? [] : [keys.SPACE]),
146+
];
140147
const navigateKeys = [keys.ARROW_LEFT, keys.ARROW_RIGHT];
141148

142149
// Clear selection when entering text input

packages/tag-input/src/styles.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
}
5656

5757
input {
58-
display: inline-block;
58+
display: flex;
59+
flex: 1 1 0%;
60+
min-width: 120px;
5961
padding-top: 0.25rem;
6062
padding-bottom: 0.25rem;
6163
padding-left: 0.5rem;

0 commit comments

Comments
 (0)