wpaccessibility / settings-api-enhanced Goto Github PK
View Code? Open in Web Editor NEWAn improved WordPress Settings API with default render callbacks and a new accessible layout.
An improved WordPress Settings API with default render callbacks and a new accessible layout.
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 the settings-field
divs. The real need is to distinguish fields that are within a section from the other ones, in order to style them properly. The settings-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.
As discussed in today's meeting (see https://wordpress.slack.com/archives/C02RQBWTW/p1496073615671126), let's remove the unnecessary .settings-field-control
element. That class should instead be used on the field element/s itself.
Note that this class name will definitely not be the name that we'll eventually use, but the name change is part of another discussion.
The Site Language select should be moved after "Week Starts On" for parity with the current WP page. See also what is already done in #16
For better readability, design consistency, and typography, any field in the Settings pages uses some bold text before the field. This also helps while visually scanning the page.
Text fields, textareas, selects, etc. can use their associated label as "bold text" before the fields.
Radio buttons are always more than 1 and when grouped in a <fieldset>
element, they can use the fieldset <legend>
element as "bold text". Same goes for checkboxes when more than one.
Single checkboxes instead don't have any semantic element that can be used as a "bold text" before the checkbox. Their associated label is on the right and must stay on the right.
We should explore what the best option is. Is it acceptable to print out some text that is used just for visual purposes (hidden from assistive technologies with aria-hidden="true"
)? Would that be easy to understand for people going to use the Settings API? Would it be abused?
Screnshot to illustrate the issue:
Worth nothing in this specific case the checkbox and the "New User Default Role" select are actually logically related, thus they should be within a <fieldset>
so the text "Membership" (maybe consider a better wording? ) could be a <legend>
. There are other cases where this is not the case though, and the issue stands.
Worth also considering that the "Anyone can register" checkbox and the "New User Default Role" select aren't so strictly related to "General settings" and probably should go in a "Membership settings" section/page. This wouldn't solve the issue of the "bold text" though.
Personally, I think single checkboxes are always a bit tricky and maybe worth exploring if this kind of setting can use a different control. Comparing with the multisite settings, there are 4 registration options, where one of them is "Registration is disabled".
So there's some inconsistency with the registration setting on a single site installation. For analogy then, maybe single site should use two radio buttons?
If I'm not wrong, the skip_title
and skip_title_screen_reader
arguments are not documented.
The field description output does basically always the same thing and could be abstracted in a method. If I'm not wrong, it currently does a slightly different thing only in the case of render_settings_field_radio()
and render_settings_field_multibox()
.
At the moment this project provides standard callbacks to output the following field types (@flixos90 please correct me if I'm wrong):
case 'text':
case 'email':
case 'url':
case 'tel':
case 'number':
case 'textarea':
case 'checkbox':
case 'select':
case 'radio':
case 'multibox': <-- multiple checkboxes
Should we add or remove support for some fields? About the number
field, @rianrietveld ran some tests and it turned out it's poorly supported by assistive technologies. I think also browsers support is pretty inconsistent. I think it's worth some discussion 🙂
Margin/padding should be figured out:
Furthermore font-size should be figured out:
<label>
, <legend>
or <span>
)In General Settings, Date Format and Time Format have a "Custom" radio button followed by a text field to enter a custom format. When using a keyboard or screen reader, when the text input field gets focused the related radio button gets selected.
Tabbing is the only way keyboard users and screen reader users have to navigate through a form, so they will very likely focus the text field but that doesn't mean they want to enter a custom format. They're just navigating the form.
To reproduce the worst scenario:
Worth considering to fix this in core whether or not the Settings Api Enhanced will get merged.
As discussed on Slack, see https://wordpress.slack.com/archives/C02RQBWTW/p1491840082372116 we should try to establish good CSS naming conventions. Also worth considering the CSS classes used for the fields can be re-used in other contexts, for example in the future Fields API and in any other part of the admin.
Some points emerged during the discussion:
.is-active
or .is-dismissible
)Minor but worth considering. In the current implementation, a couple of times there's a check for is_callable() / is_string()
. This could be re-used more and more in the future, and could maybe be abstracted in a utility method.
There are cases where it would be worth grouping multiple fields within a fieldset element with a legend. Should add_settings_section()
optionally output a fieldset with legend?
Initially mentioned by @joehoyle in https://make.wordpress.org/core/2017/05/22/enhanced-settings-api-where-were-at/#comment-32484:
Settings can be registered for the REST API with information on their data type. For those fields where that data is available, we could use it to use sane defaults, for example use field type number
if the field is registered as integer
/float
/number
.
Worth noting that we'll still need add_settings_field()
because register_setting()
deals with the data itself, not the UI. Furthermore in the Settings API we'll often use data stored in serialized arrays (thanks WordPress), which can't be handled easily in the REST API at the moment. But it could indeed help with defaults.
Leftover 😬
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
in
wp-admin/options-media.php
As discussed in today's meeting (see https://wordpress.slack.com/archives/C02RQBWTW/p1496073615671126), let's remove the wrap element since it's unnecessary.
render_settings_field_multibox()
perfectly works for a group of checkboxes sharing the same name
attribute. That is, a multi-choice where users can check multiple values for the same group.
This works in HTML but it's arguable useful for settings since there's rarely (never?) a setting with multiple values.
Instead, the current group of checkboxes in core are all single settings with a unique name
attribute. They're visually grouped because logically related. However, the don't use the same setting name.
How to render a group like the following one?
The only way right now would be a custom callback 😞
I'm really digging the new way to present the information on the Settings pages, but visually I got a bit of a cluttered, disjointed feeling from glancing over the page. It's hard to describe, but it felt like it was hard to grasp what belonged together, a sort of mental noise. So I tweaked some CSS to see if I could get rid of that feeling. Tell me what you think:
settings-field-title
to 5px 0
(from 5px 10px 10px 0
) to pull the fields and their titles closer togetherborder-top: 1px solid #cccccc;
with margin-bottom reduced to 30px)Noticed just know 😞 the custom structure field has the same keyboard trap that was in the General settings date/time custom format. Fixed in core in https://core.trac.wordpress.org/ticket/40515 and in this plugin in #26
For core, will open a Trac ticket.
Apart from following the WordPress CSS coding standards, the CSS should also use some best practices. The first one that come into my mind (but there are a lot) are, for example:
1
Don't use element selectors if not strictly necessary. Things like
.settings-fields p.timezone-info
could be simply
.settings-fields .timezone-info
2
Don't use element selectors and also lower specificity as much as possible. Selectors like
.settings-fields .settings-field-control p
should be just
.settings-fields .description
More example welcome.
Splitting this out from #6
See also discussion on Slack during Settings API meeting:
https://wordpress.slack.com/archives/C02RQBWTW/p1493049728130607
The main goal should be establishing a solid convention for naming CSS classes or ID attributes meant to be exclusively used for JS targeting. Quoting from Helen's doc"
Reusing styling class names is fragile and obscures intent when doing long-term maintenance.
As previously discussed in #38, we need to figure out a good way to handle radio groups with a custom text element.
There are currently three cases in core settings:
What makes this even more complex is that all three fields contain an additional component: some kind of example (date format / time format / URL structure respectively). In the case of the Permalink Structure field, the example is even combined with the text field.
Let's think about how we can create clean markup for these fields which is accessible and at the same time visually clear.
Currently, the General Settings screen only uses sections for their visual padding.
I think it would be useful to add headings to at least a few of them. In particular, I'm thinking about making the "Membership" text for the "Anyone can register" checkbox its own section heading, which would then contain that checkbox plus new user default role dropdown. This would furthermore fix #5 for this specific field.
Since all the following fields belong together as they deal with the locale (so completely unrelated to "Membership"), the section needs an actual heading as well (probably "Locale").
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.