securingsincity/react-ace

Conditionally setting className removes ace-editor class

Open

#823 ouverte le 13 avr. 2020

Voir sur GitHub
 (1 commentaire) (3 réactions) (0 assignés)JavaScript (615 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (3 859 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Problem

When I am conditionally setting the className prop for an error - the editor position changes and breaks the UI.

For example: I set a className for an error. Once there is no longer an error, I am passing in an empty string. When inspecting the DOM, I noticed that the ace-editor class is getting removed.

After looking at the source code, I found this section which I believe is the culprit. If I am reading it correctly, I believe if there was a previous class name and the new class name is falsy, it would remove one of the libraries set class names (ace-editor).

Sample code to reproduce your issue

Conditional className prop:

className={error ? classes.error : ""}

Steps on how I am able to get this issue:

  • Type in editor (starts with no className)
  • Submit w/ error (updates className to error)
  • Type more in editor (updates className to "")
  • Submit w/ another error (updates className to error)

Guide contributeur