popcodeorg / popcodeorg/popcode
validation on canvas element incorrectly flags 'width' attribute as an error
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 191
- Forks
- 143
- Merge moyen
- 4 j 11 h
- PR mergées (30 j)
- 5
Description
I'm trying to use a <canvas> element (for a Tiny Turtle exercise) and set its width to something larger than the default of 300px. Naively I tried a css rule:
canvas {
width: 100%;
min-height: 400px;
}
But with <canvas>, a css-specified width actually scales the content. This makes the turtle head and line segments appear quite large and even pixellated and does not actually give any more room to draw.
MDN recommends instead that you set the width and height directly on the element. Trying this triggered a popcode validation error on width:
9
Don't use the "width" attribute. Instead, use the CSS width property
Impact: mostly a little annoying. You can't set the real width of the canvas, so there will be unused space at the right margin -- and quite noticeable with a bigger screen. Complicated turtle drawings may not fit well into 300x150 px (although for some reason the height attribute is allowed through validation, so the canvas can be made taller).
Also, the validator-recommended fix isn't a real fix, which is minor in and of itself but we'd like users to be able to rely on its recommendations.
Steps to reproduce:
- Open this popcode link: https://popcode.org/?gist=1791db30a9fa1cbcc39e0ec181388634
- In the html panel, set the
<canvas>element's width attribute to, say, 400. Observe the validation error. - Observe the somewhat-pixellated turtle stamp render (due to the css width being set w/o html width).
- Observe the rendered length of a
forward(30)segment. Cut thatforwarddown to 10 units to allow more drawing room. Observe that the stamp now overwhelms the line segment.
On a page without validation, eg jsbin, setting the width attr has the desired result of setting the canvas's coordinate system width (which can then optionally be scaled with css).
Tested on macos 10.11 with Safari 10.0.3 and Chrome 56.0.2924.87.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez l’erreur de validation à l’aide du gist Popcode lié, en vous concentrant sur un élément canvas doté d’un attribut width et sur le message du validateur recommandant CSS width. Suivez le point d’entrée du validateur qui émet ce message et comparez son traitement de width à celui de height. La tâche est terminée lorsqu’une largeur canvas valide est acceptée et que la recommandation ne contredit plus le comportement de dimensionnement de canvas.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- html, javascript
- Domaine
- frontend, testing-qa, web-dev
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100