bard-tag_field 0.4.1 → 0.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbfde3758dcf03243548db95eb9901f43cbcccbe5eac3a2dc1d64ecee31aaa60
4
- data.tar.gz: d7f453d7ad5f9ac62b3a41ae5d8304c8bb01d230059ad630641440b6949622a3
3
+ metadata.gz: 7a90b26ef508ec001cae14170b6ce96c543d6610c984622a1a2f3d9722c3e713
4
+ data.tar.gz: 5bafffc31b38325321042c768d96cb9d4b7f829a8d05f803d9f6bb96d38c85e1
5
5
  SHA512:
6
- metadata.gz: c30cc6a3b8d25fc4a3c9ca0a17c548ae13c785ac437ffbdae5bddfdd3e1f96d95fee9987e2096888cf561e1c9d64ab555124118d24fc35b50afea0e549295d8b
7
- data.tar.gz: f521b1e6907f65230310c1a17890a07519da7756efc9ad3b6f2f1047c5d9ec2874b597e2aaf9dc066c6bb4a77104416694593935b096d1e788a67bd5c0675083
6
+ metadata.gz: ca88e6931e551b19f280e6ecec610251c44b7778ebc88b93693ce3b9a3f05df800d9743b5bf58bf9d97f45bb542be0fae5e8a64ad6d04a5dbd813dac455eeb79
7
+ data.tar.gz: 61013f52ca3daadefc24a4d1a7f3346d392a31ebefd2c144ddd2490975d4a51a6d27d840fb818bdbdf463256661f1dd655915e7e6f2c237c5b4f99f16ad7e402
@@ -1120,8 +1120,17 @@ class InputTag extends HTMLElement {
1120
1120
 
1121
1121
  processTagOptions() {
1122
1122
  if(!this._taggle || !this._taggle.tag) return
1123
- const tagOptions = Array.from(this.children).filter(e => e.tagName === 'TAG-OPTION');
1124
- const values = tagOptions.map(e => e.value).filter(value => value !== null && value !== undefined);
1123
+ let tagOptions = Array.from(this.children).filter(e => e.tagName === 'TAG-OPTION');
1124
+ let values = tagOptions.map(e => e.value).filter(value => value !== null && value !== undefined);
1125
+
1126
+ // Enforce maxTags constraint for single mode
1127
+ if (!this.multiple && values.length > 1) {
1128
+ // Remove excess tag-options from DOM (keep only the first one)
1129
+ tagOptions.slice(1).forEach(el => el.remove());
1130
+ tagOptions = tagOptions.slice(0, 1);
1131
+ values = values.slice(0, 1);
1132
+ }
1133
+
1125
1134
  this._taggle.tag.elements = tagOptions;
1126
1135
  this._taggle.tag.values = values;
1127
1136
  this._inputPosition = this._taggle.tag.values.length;
@@ -1136,6 +1145,9 @@ class InputTag extends HTMLElement {
1136
1145
 
1137
1146
  // Update internal value to match
1138
1147
  this.updateValue();
1148
+
1149
+ // Ensure input visibility is updated when tags change via DOM
1150
+ this.updateInputVisibility();
1139
1151
  }
1140
1152
 
1141
1153
  get form() {
@@ -1146,9 +1158,13 @@ class InputTag extends HTMLElement {
1146
1158
  return this.getAttribute("name");
1147
1159
  }
1148
1160
 
1161
+ get multiple() {
1162
+ return this.hasAttribute('multiple');
1163
+ }
1164
+
1149
1165
  get value() {
1150
1166
  const internalValue = this._internals.value;
1151
- if (this.hasAttribute('multiple')) {
1167
+ if (this.multiple) {
1152
1168
  return internalValue; // Return array for multiple mode
1153
1169
  } else {
1154
1170
  return internalValue.length > 0 ? internalValue[0] : ''; // Return string for single mode
@@ -1173,7 +1189,7 @@ class InputTag extends HTMLElement {
1173
1189
  values.forEach(value => formData.append(this.name, value));
1174
1190
  // For single mode, append empty string when no values (like standard HTML inputs)
1175
1191
  // For multiple mode, leave empty (like standard HTML multiple selects)
1176
- if (values.length === 0 && !this.hasAttribute('multiple')) {
1192
+ if (values.length === 0 && !this.multiple) {
1177
1193
  formData.append(this.name, "");
1178
1194
  }
1179
1195
  this._internals.setFormValue(formData);
@@ -1379,7 +1395,6 @@ class InputTag extends HTMLElement {
1379
1395
  this.inputTarget = this.shadowRoot.querySelector("#inputTarget");
1380
1396
 
1381
1397
  this.required = this.hasAttribute("required");
1382
- this.multiple = this.hasAttribute("multiple");
1383
1398
 
1384
1399
  const maxTags = this.multiple ? undefined : 1;
1385
1400
  const placeholder = this.inputTarget.getAttribute("placeholder");
@@ -1443,6 +1458,12 @@ class InputTag extends HTMLElement {
1443
1458
  },
1444
1459
  render: item => h(`<li class="ui-menu-item" data-value="${item.value}">${item.label}</li>`),
1445
1460
  onSelect: item => {
1461
+ // Prevent adding multiple tags in single mode
1462
+ if (!this.multiple && this._taggle.getTagValues().length > 0) {
1463
+ this._taggleInputTarget.value = '';
1464
+ return
1465
+ }
1466
+
1446
1467
  // Create a tag-option element with proper value/label separation
1447
1468
  const tagOption = document.createElement('tag-option');
1448
1469
  tagOption.setAttribute('value', item.value);
@@ -1580,7 +1601,7 @@ class InputTag extends HTMLElement {
1580
1601
  values.forEach(value => formData.append(this.name, value));
1581
1602
  // For single mode, append empty string when no values (like standard HTML inputs)
1582
1603
  // For multiple mode, leave empty (like standard HTML multiple selects)
1583
- if (values.length === 0 && !this.hasAttribute('multiple')) {
1604
+ if (values.length === 0 && !this.multiple) {
1584
1605
  formData.append(this.name, "");
1585
1606
  }
1586
1607
  this._internals.setFormValue(formData);
@@ -1643,10 +1664,9 @@ class InputTag extends HTMLElement {
1643
1664
  updateInputVisibility() {
1644
1665
  if (!this._taggleInputTarget || !this.buttonTarget) return;
1645
1666
 
1646
- const isMultiple = this.hasAttribute('multiple');
1647
1667
  const hasTags = this._taggle && this._taggle.getTagValues().length > 0;
1648
1668
 
1649
- if (isMultiple) {
1669
+ if (this.multiple) {
1650
1670
  // Multiple mode: always show input and button
1651
1671
  this._taggleInputTarget.style.display = '';
1652
1672
  this.buttonTarget.style.display = '';
@@ -1715,9 +1735,6 @@ class InputTag extends HTMLElement {
1715
1735
  handleMultipleChange(isMultiple) {
1716
1736
  if (!this._taggle) return;
1717
1737
 
1718
- // Update the internal multiple state
1719
- this.multiple = isMultiple;
1720
-
1721
1738
  // Get current tags
1722
1739
  const currentTags = this._taggle.getTagValues();
1723
1740
 
@@ -1816,7 +1833,7 @@ class InputTag extends HTMLElement {
1816
1833
  values.forEach(value => formData.append(this.name, value));
1817
1834
  // For single mode, append empty string when no values (like standard HTML inputs)
1818
1835
  // For multiple mode, leave empty (like standard HTML multiple selects)
1819
- if (values.length === 0 && !this.hasAttribute('multiple')) {
1836
+ if (values.length === 0 && !this.multiple) {
1820
1837
  formData.append(this.name, "");
1821
1838
  }
1822
1839
  this._internals.setFormValue(formData);
data/bard-tag/bun.lockb CHANGED
Binary file
@@ -5,11 +5,11 @@
5
5
  "build": "rollup -c"
6
6
  },
7
7
  "devDependencies": {
8
- "@rollup/plugin-commonjs": "^25.0.7",
9
- "@rollup/plugin-node-resolve": "^15.2.3",
10
- "rollup": "^4.5.2"
8
+ "@rollup/plugin-commonjs": "^28.0.8",
9
+ "@rollup/plugin-node-resolve": "^16.0.3",
10
+ "rollup": "^4.52.5"
11
11
  },
12
12
  "dependencies": {
13
- "@botandrose/input-tag": "0.3.0"
13
+ "@botandrose/input-tag": "0.4.2"
14
14
  }
15
15
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module TagField
5
- VERSION = "0.4.1"
5
+ VERSION = "0.4.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-tag_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-27 00:00:00.000000000 Z
11
+ date: 2025-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails