Skip to content

Commit 16212ee

Browse files
author
Sara Dahan
committed
fix(label-group): make collapsedText placeholder generic
1 parent 89c762f commit 16212ee

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

elements/pf-label-group/pf-label-group.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { LitElement, html, type TemplateResult } from 'lit';
32
import { customElement } from 'lit/decorators/custom-element.js';
43
import { property } from 'lit/decorators/property.js';
@@ -23,10 +22,6 @@ export class PfLabelGroupExpandEvent extends Event {
2322
}
2423
}
2524

26-
/**
27-
* Regex used to replace the `${remaining}` variable in collapsed text.
28-
*/
29-
const REMAINING_RE = /\$\{\s*remaining\s*\}/g;
3025

3126
/**
3227
* A **label group** is a collection of labels that can be grouped by category
@@ -236,14 +231,24 @@ export class PfLabelGroup extends LitElement {
236231
});
237232

238233
const rem = Math.max(0, labels.length - this.numLabels);
239-
this._overflowText = rem < 1 ?
240-
''
241-
: this.open ?
242-
this.expandedText
243-
: this.collapsedText.replace(REMAINING_RE, rem.toString());
244-
245-
if (rem < 1 && this.open) {
246-
this.open = false;
234+
235+
if (rem < 1) {
236+
this._overflowText = '';
237+
if (this.open) {
238+
this.open = false;
239+
}
240+
} else {
241+
const placeholderMatch = this.collapsedText.match(/\$\{.*?\}/);
242+
if (placeholderMatch) {
243+
const [placeholder] = placeholderMatch;
244+
this._overflowText = this.collapsedText.replace(placeholder, rem.toString());
245+
} else {
246+
this._overflowText = this.collapsedText;
247+
}
248+
249+
if (this.open) {
250+
this._overflowText = this.expandedText;
251+
}
247252
}
248253
}
249254
}

0 commit comments

Comments
 (0)