diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ec0f2..e381a6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] ### Changed -- Clean up mixed Chartist imports +- Clean up mixed Chartist imports ([#2](https://github.com/stklcode/chartist-plugin-tooltip/pull/2)) + +### Fixed +- Fixed support for multiple custom classes as an array ([#3](https://github.com/stklcode/chartist-plugin-tooltip/pull/3)) ## [2.0.0] - 18th April 2026 diff --git a/src/scripts/chartist-plugin-tooltip.ts b/src/scripts/chartist-plugin-tooltip.ts index 16d967e..60fdfa0 100644 --- a/src/scripts/chartist-plugin-tooltip.ts +++ b/src/scripts/chartist-plugin-tooltip.ts @@ -106,9 +106,15 @@ export default function ChartistPluginTooltip>( } if (!tt) { tt = document.createElement('div'); - tt.className = $options.class - ? 'chartist-tooltip ' + $options.class - : 'chartist-tooltip'; + tt.classList.add('chartist-tooltip'); + if ($options.class) { + tt.classList.add( + ...([] as string[]) + .concat($options.class) + .flatMap(c => c.split(/\s+/)) + .filter(Boolean) + ); + } if ($options.appendToBody) { document.body.appendChild(tt); } else { diff --git a/test/chartist-plugin-tooltip.spec.ts b/test/chartist-plugin-tooltip.spec.ts index 53a7d4a..d1fece7 100644 --- a/test/chartist-plugin-tooltip.spec.ts +++ b/test/chartist-plugin-tooltip.spec.ts @@ -39,7 +39,7 @@ describe('Tooltips plugin', () => { }, { plugins: [ - [ChartistPluginTooltip, {class: 'foo', appendToBody: false}] + [ChartistPluginTooltip, {class: ['foo', 'bar'], appendToBody: false}] ] } ); @@ -120,7 +120,8 @@ describe('Tooltips plugin', () => { assert.equal(getTooltip()!.style.top, '190px'); }); - it('should set additional class', function () { + it('should set additional classes', () => { assert.equal(hasClass(getTooltip()!, 'foo'), true); + assert.equal(hasClass(getTooltip()!, 'bar'), true); }); });