Skip to content

Commit dbbc3ab

Browse files
committed
Fix support for multiple custom classes as array (#3)
Using the "class" option for a single class string or a space-separated list of classes in a single string works fine. Type and docs claim support for a list/array of classes which results in invalid output "chartist-tooltip class1,class2". Rework the logic and properly map arrays without breaking the current behavior.
1 parent ca0381a commit dbbc3ab

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [unreleased]
99

1010
### Changed
11-
- Clean up mixed Chartist imports
11+
- Clean up mixed Chartist imports ([#2](https://github.com/stklcode/chartist-plugin-tooltip/pull/2))
12+
13+
### Fixed
14+
- Fixed support for multiple custom classes as an array ([#3](https://github.com/stklcode/chartist-plugin-tooltip/pull/3))
1215

1316

1417
## [2.0.0] - 18th April 2026

src/scripts/chartist-plugin-tooltip.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ export default function ChartistPluginTooltip<T extends BaseChart<any>>(
106106
}
107107
if (!tt) {
108108
tt = document.createElement('div');
109-
tt.className = $options.class
110-
? 'chartist-tooltip ' + $options.class
111-
: 'chartist-tooltip';
109+
tt.classList.add('chartist-tooltip');
110+
if ($options.class) {
111+
tt.classList.add(
112+
...([] as string[])
113+
.concat($options.class)
114+
.flatMap(c => c.split(/\s+/))
115+
.filter(Boolean)
116+
);
117+
}
112118
if ($options.appendToBody) {
113119
document.body.appendChild(tt);
114120
} else {

test/chartist-plugin-tooltip.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Tooltips plugin', () => {
3939
},
4040
{
4141
plugins: [
42-
[ChartistPluginTooltip, {class: 'foo', appendToBody: false}]
42+
[ChartistPluginTooltip, {class: ['foo', 'bar'], appendToBody: false}]
4343
]
4444
}
4545
);
@@ -120,7 +120,8 @@ describe('Tooltips plugin', () => {
120120
assert.equal(getTooltip()!.style.top, '190px');
121121
});
122122

123-
it('should set additional class', function () {
123+
it('should set additional classes', () => {
124124
assert.equal(hasClass(getTooltip()!, 'foo'), true);
125+
assert.equal(hasClass(getTooltip()!, 'bar'), true);
125126
});
126127
});

0 commit comments

Comments
 (0)