Bug: lexicalNode.getStyle does not read the elements computed css properties
- Dominant language
- TypeScript
- Stars
- 23.9k
- Forks
- 2.2k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 61
Description
If you were to create a heading element in the lexical playground and select a word within that heading, the font size in the toolbar would not update.`$getSelectionStyleValueForProperty` is calling on the `getStyle` function from the lexicalNodes inside of the selection, but this method expects the style to be set inline.
The issue is when the font-size styling of `p`,`h1`,`h2`, etc elements are styled using css through the theme. These elements are styled through a className and not inline, or the style is inherited from the parent element. In this case the selection is not found and the default value is always used. I expect a method like `getSelectionStyleValueForProperty` to return the actual style of the element and not an inline style since this could ignore stylesheets
A possible workaround is to set the expected font-size as inline styling when the heading element is created. This should let the `getStyle` read the inline style and update correctly. A better workaround is to provide access to the underlying element and call `window.getComputedStyle`.
https://github.com/facebook/lexical/assets/58753718/f3f7e8a4-2ec9-49bf-b60b-fb4f3c202cd8
Contributor guide
Research direction
Reproduce the issue in the Lexical playground by selecting text in a heading whose font size comes from a theme class or inherited CSS. Trace `$getSelectionStyleValueForProperty` through the lexical nodes' `getStyle` method and verify that the completed behavior reflects computed element styles rather than only inline styles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100