Skip to content

Commit

Permalink
fix: the \class command in a math-field would not pickup classes defi…
Browse files Browse the repository at this point in the history
…ned inside the math-field
  • Loading branch information
arnog committed Aug 18, 2023
1 parent a93c3f9 commit 5a1c363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **#2018** Some VK toolbar items could be offset by a few pixels on some
mobile devices
- The caret was not visible when placed after an `\operator*{}` command
- The `\class{}{}` command in a mathfield was not working correctly.

### Improvements

Expand Down
20 changes: 20 additions & 0 deletions src/public/mathfield-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@ export class MathfieldElement extends HTMLElement implements Mathfield {
*/
private _internals: ElementInternals;

// The content of <style> tags inside the element.
/** @internal */
private _style: string;

/**
* To create programmatically a new mathfield use:
*
Expand Down Expand Up @@ -1734,6 +1738,22 @@ import 'https://unpkg.com/@cortex-js/compute-engine?module';

const slot =
this.shadowRoot!.querySelector<HTMLSlotElement>('slot:not([name])');
try {
this._style = slot!
.assignedElements()
.filter((x) => x.tagName.toLowerCase() === 'style')
.map((x) => x.textContent)
.join('');
} catch (error: unknown) {
console.error(error);
}
// Add shadowed stylesheet if one was provided
// (this is important to support the `\class{}{}` command)
if (this._style) {
const styleElement = document.createElement('style');
styleElement.textContent = this._style;
this.shadowRoot!.appendChild(styleElement);
}

let value = '';
// Check if there is a `value` attribute and set the initial value
Expand Down

0 comments on commit 5a1c363

Please sign in to comment.