-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate labels to enclosing, plus other testing/fixing #37552
base: main
Are you sure you want to change the base?
Conversation
…all of those files, proofreading changes and trying out the examples. Many of them were originally broken; I tried to fix as many as possible. Some of the examples were uninspired or didn't demonstrate the methods very well, so I added prose or refactored.
Preview URLs (33 pages)
Flaws (759)URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
URL:
External URLs (1)URL:
|
@@ -45,16 +45,22 @@ When set on a file input type, the native file picker that opens up should only | |||
|
|||
```html | |||
<p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typical changes I made. Checkboxes and Radios put the label text After the <input; other inputs (like this) put the text before.
@@ -120,7 +120,7 @@ When form controls are disabled, many browsers will display them in a lighter, g | |||
</fieldset> | |||
``` | |||
|
|||
{{EmbedLiveSample('Examples', 500, 450)}} | |||
{{EmbedLiveSample('Examples', 500, 560)}} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes I made the box taller.
@@ -145,9 +147,11 @@ input:valid + span::after { | |||
} | |||
``` | |||
|
|||
Notice that the `span` has to come immediately after the `input` element, in order for the `input + span` css selector to work. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of the examples use the same technique to indicate valid ✔︎ or invalid ✘. It was easy to break these; that's when I decided I had to test each one of these before I was done.
background: #f00; | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternate validity mechanism - I thought this seemed more appropriate for the situation
margin-block: 1em; | ||
} | ||
``` | ||
|
||
```html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example just seemed boring, and didn't illustrate different combinations (more items than size, less items than size, same number).
<label> | ||
enter a breed of dog: | ||
<input type="text" value="corgi" size="45" /> | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra long size
<label> | ||
enter a breed of cat: | ||
<input type="text" value="cheshire" size="4" /> | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra short size
<option value="11:00 am"></option> | ||
<option value="12:00 pm"></option> | ||
<option value="13:00 pm"></option> | ||
<option value="14:00 pm"></option> | ||
</datalist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed kindof contrived with only 3 slots
@@ -109,7 +110,7 @@ You can use the [`min`](/en-US/docs/Web/HTML/Element/input#min) and [`max`](/en- | |||
|
|||
{{EmbedLiveSample('Setting_maximum_and_minimum_dates', 600, 40)}} | |||
|
|||
The result is that only days in April 2017 can be selected — the month and year parts of the textbox will be uneditable, and dates outside April 2017 can't be selected in the picker widget. | |||
The result is that only days in April 2017 can be selected — the month and year parts of the textbox will be uneditable, and dates outside April 2017 can't be selected in the picker widget. (The user might be able to click and type in day, month and year, depending on the browser.) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just based on my playing around with Chrome, Firefox and Safari
<span class="validity"></span> | ||
<label> | ||
Enter your birthday: | ||
<input type="date" name="bday" value="1995-01-01" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a value cuz it didn't look insightful
@@ -11,23 +11,21 @@ browser-compat: html.elements.input.type_datetime-local | |||
|
|||
{{EmbedInteractiveExample("pages/tabbed/input-datetime-local.html", "tabbed-shorter")}} | |||
|
|||
The control's UI varies in general from browser to browser. In browsers with no support, these degrade gracefully as if [`<input type="text">`](/en-US/docs/Web/HTML/Element/input/text) were set. | |||
The control's UI varies in general from browser to browser. In browsers with no support, these degrade gracefully as if [`<input type="text">`](/en-US/docs/Web/HTML/Element/input/text) were set. More modern implementations have an icon on the side that brings up a calendar panel where the user can select a date and time. Also, the user can often just enter numbers by clicking and typing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browser behavior seems to have changed over the years since this was written
|
||
The control is intended to represent _a local date and time_, not necessarily _the user's local date and time_. In other words, the input allows any valid combination of year, month, day, hour, and minute—even if such a combination is invalid in the user's local time zone (such as the one hour within a daylight saving time spring-forward transition gap). | ||
|
||
## Value | ||
|
||
A string representing the value of the date entered into the input. The format of the date and time value used by this input type is described in [Local date and time strings](/en-US/docs/Web/HTML/Date_and_time_formats#local_date_and_time_strings). | ||
A string representing the value of the date entered into the input. The format of the date and time value used by this input type is described in [Local date and time strings](/en-US/docs/Web/HTML/Date_and_time_formats#local_date_and_time_strings). It's similar to [ISO8601](<https://en.wikipedia.org/wiki/ISO_8601#Local_time_(unqualified)>). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm familiar with ISO so I know how it looks.
min="2017-06-01T08:30" | ||
max="2017-06-30T16:30" | ||
required /> | ||
<span class="validity"></span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's this <span that turns into a check ✔︎
or x ✘
@@ -9,6 +9,8 @@ browser-compat: html.elements.input.type_file | |||
|
|||
{{HTMLElement("input")}} elements with **`type="file"`** let the user choose one or more files from their device storage. Once chosen, the files can be uploaded to a server using [form submission](/en-US/docs/Learn_web_development/Extensions/Forms), or manipulated using JavaScript code and [the File API](/en-US/docs/Web/API/File_API/Using_files_from_web_applications). | |||
|
|||
The user can click the button to bring up a file selection dialog, or they can just drag the file into the button. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see people using the dialog all the time, not realizing you can just drag & drop. At least the developers will know.
@@ -117,7 +117,7 @@ Let's look at a basic example that includes all the essential features you'd nee | |||
|
|||
```html | |||
<input | |||
id="image" | |||
id="loginImageButton" | |||
type="image" | |||
width="100" | |||
height="30" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, lots of things were named 'image'. I wanted to say, no, they don't all have to be the same names.
@@ -118,6 +120,8 @@ Here, we have an `number` input with the placeholder "Multiple of 10". Note how | |||
|
|||
{{EmbedLiveSample('Placeholders', 600, 40)}} | |||
|
|||
Of course, the user can still type in any number they want. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't clear from the context
min="4" | ||
max="107" /> | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
illustrate that you can start at a number that isn't a multiple of the stepsize
switchBtn.setAttribute("class", "feet"); | ||
switchBtn.value = "Enter height in meters"; | ||
if (switchBtn.classList.contains("meters")) { | ||
// switch to feet and inches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of deciding based on the whole class string, just search for the speific class keyword with array.contains()
let m = inches / 39.37; | ||
output.textContent = `${m.toFixed(2)} meters, or ${ft} feet ${inch.toFixed(0)} inches`; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
display in both forms
required | ||
autocomplete="new-password" /> | ||
<span class="validity"></span> | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added validity <span so the example actually does something
@@ -19,6 +19,8 @@ They are called radio buttons because they look and operate in a similar manner | |||
|
|||
> **Note:** [Checkboxes](/en-US/docs/Web/HTML/Element/input/checkbox) are similar to radio buttons, but with an important distinction: radio buttons are designed for selecting one value out of a set, whereas checkboxes let you turn individual values on and off. Where multiple controls exist, radio buttons allow one to be selected out of them all, whereas checkboxes allow multiple values to be selected. | |||
|
|||
The set of `N` radio buttons actually has `N + 1` states: each one selected, and then none selected. The user can't set it to this last state, and it's pretty useless; but it's legal and your app might set it that way by accident. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something about radios that isn't obvious at first
@@ -54,7 +62,7 @@ The resulting HTML looks like this: | |||
</form> | |||
``` | |||
|
|||
Here you see the three radio buttons, each with the `name` set to `contact` and each with a unique `value` that uniquely identifies that individual radio button within the group. They each also have a unique {{domxref("Element.id", "id")}}, which is used by the {{HTMLElement("label")}} element's [`for`](/en-US/docs/Web/HTML/Element/label#for) attribute to associate the labels with the radio buttons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no unique ID needed with enclosing labels
<span class="validity"></span> | ||
<button>Search</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separating the span.validity from the input breaks the check & x, so I fixed it
<button>Search</button> | ||
<span class="validity"></span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
span.validity must be contiguous to <input
@@ -107,14 +107,14 @@ It's important, however, to note that this is not enough to ensure that the spec | |||
This element is implemented as a standard text input field with basic validation features. In its most basic form, a URL input can be implemented like this: | |||
|
|||
```html | |||
<input id="myURL" name="myURL" type="url" /> | |||
<input id="myURL" name="myURL" type="url" value="https://mozilla.org" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was a bit mysterious without some text already in it
|
||
There is nothing magical going on here. Submitting this form would cause the following data to be sent to the server: `myURL=http%3A%2F%2Fwww.example.com`. Note how characters are escaped as necessary. | ||
There is nothing magical going on here. Submitting this form would cause the following data to be sent to the server: `myURL=https%3A%2F%2Fmozilla.org`. Note how characters are escaped as necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everybody uses https these days, not so much http
id="myURL" | ||
name="myURL" | ||
type="url" | ||
size="60" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanted to really accentuate the effect of a high size
Description
Converted '<label for=id' instances to enclosing labels, in Live Samples, in en-us/web/html directory. Also tested and fixed some of the examples.
THIS PR IS NOT NEARLY AS INTIMIDATING AS IT SEEMS!
see below.
Motivation
Unfortunately, the for=ID method requires that you have to make up a sometimes arbitrary ID for each instance. Often, there is no other reason for that ID. For large pages, if a nontrivial widget appears in many places in the site, each might need a unique string to put into its ID(s).
The for=ID method appears in almost all cases in examples in MDN. This leads to the impression that no other method is available, and that misconception is propagated.
Additional details
THIS PR IS NOT NEARLY AS INTIMIDATING AS IT SEEMS! Although the size is XL, most of the changes are the same thing over and over again:
See also the <label> element
First section describes how you can use either method. I think in the early days, the enclosure method didn't work reliably so people got in the habit of using the for=ID method.
Related issues and pull requests