popcodeorg / popcodeorg/popcode

validation on canvas element incorrectly flags 'width' attribute as an error

Aperta
#671 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
JavaScript
Stelle
191
Fork
143
Merge medio
4g 11h
PR unite (30g)
5

Descrizione

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:

  1. Open this popcode link: https://popcode.org/?gist=1791db30a9fa1cbcc39e0ec181388634
  2. In the html panel, set the <canvas> element's width attribute to, say, 400. Observe the validation error.
  3. Observe the somewhat-pixellated turtle stamp render (due to the css width being set w/o html width).
  4. Observe the rendered length of a forward(30) segment. Cut that forward down 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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci l’errore di validazione usando il gist Popcode collegato, concentrandoti su un elemento canvas con un attributo width e sul messaggio del validator che raccomanda CSS width. Traccia il punto di ingresso del validator che emette questo messaggio e confronta il trattamento di width con quello di height. Il lavoro è completato quando una width valida di canvas viene accettata e la raccomandazione non contraddice più il comportamento di dimensionamento di canvas.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
html, javascript
Ambito
frontend, testing-qa, web-dev
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.