-
Notifications
You must be signed in to change notification settings - Fork 0
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
Avoid divitis #7
Comments
I don't agree that the above is a valid case of "divitis". While there are quite some nested divs, I think they are necessary to provide the required structure: In the above example, you're right that the
This is necessary in my opinion since we cannot control the output for the fields themselves, since it is produced in callbacks (often by external developers). By providing markup such as the
Are you saying we need to apply |
I kindly disagree. While I understand the programmatic-oriented approach, this is just not the way markup and CSS should be used. We're basically replicating the same potential issues given by the table cells, wrapping anything within some element. Ideally, markup should always be minimal. Adding several, not semantic, divs and spans just for the sake of styling would bring us back in time by 15 years or so :) WordPress should always show best practices, and I'm afraid I wouldn't support defining the current output a best practice. Let's try to have a good balance between ease of use and clean, minimal markup and CSS. Let's analyse what the settings API need in this context. This project aims to provide standardized callbacks for a set of form fields and allow custom fields. About the former group, we know which fields will be output and we can just target them with CSS. WordPress currently does that using the type selector, and I don't see the need to change that. Say in the future support for other fields will be About the About custom fields, we just can't predict what devs will use. I doubt a wrapping Overall, I understand the good intention to cover all the possible cases, but that would be inevitably based on assumptions. Instead, I'd strongly recommend to keep everything as minimal as possible. |
You're starting to convince me. So as far as I understand you're suggesting the following: Remove the Remove the |
I forgot to answer about the Basically, the Depending on the nature of the grouped fields, the quality of their label, and the "question" they ask, using a fieldset+legend might be absolutely necessary or less useful. Consider for example this case (taken from the wp-signup page from a WordPress multisite install): In this case, tabbing to the radio buttons and then using the arrows will announce just "Yes" and "No". Users won't have any clue about the question they should answer to. The fieldset legend would solve this issue, because it is announced when tabbing into the fieldset. Worth considering, most screen readers (wrongly?) announce the legend for any field inside the fieldset so it's better to avoid a very long legend text and keep it as short as possible. In other cases, using a fieldset+legend might still make sense but if the question asked is already clear enough from the context and the field labels, it's less useful and could also introduce too much noise. It depends on a case by case basis. See the second example in the post linked above: Without the In the following example instead, I've intentionally added a "Personal details" legend. Users get this page after they click on a "Add new user" link and the page already has a "Add New User" heading: In this case, I'd say having the legend text "Personal details" repeated for each field:
would be noisy and a bit redundant, since "the question to answer to" and the context are already clear. Back to the current output, I think this condition that prints out a fieldset or a div should be improved a bit: |
I'd agree and personally prefer to target elements in the simplest possible way: with classes. I'm not sure we all agreed during yesterday's meeting on Slack though 🙂 |
Couple quick notes:
|
Your explanations regarding when to use a
I think we should print always print an element at that location, whether it's a fieldset or not. The tree structure of classes should be similar for all fields and not dependent on whether a field is semantically different from another. Applying the margin is already an argument why leaving the |
Summarizing today's discussion (see https://wordpress.slack.com/archives/C02RQBWTW/p1496073615671126), we agreed on using the following structure:
Class names are subject to change (and they will change), but this is the markup / nesting levels planned. #22 and #23 will handle the changes to ensure the above markup. |
We should avoid to print out too many
<div>
elements.See in the screenshot below what, at the moment, the API outputs for a section with two fields:
As I see it, there's no need for both the
settings-fields
and thesettings-field
divs. The real need is to distinguish fields that are within a section from the other ones, in order to style them properly. Thesettings-section
already gives us what we need.Unless I'm missing something, the inner divs could be safely removed.
I'm also concerned about the
settings-field-control
span element, used as a wrapper for the actual output from the field callback. Styling should be applied directly on the fields. I'm not really sure we need this additional<span>
.Note: when form controls are logically related and can be grouped under a "question" that relates to them all, the wrapper element should be a
<fieldset>
element with a<legend>
. This is 99% true in the case of a group of radio buttons and should be evaluated on a case by case basis for other groups.The text was updated successfully, but these errors were encountered: