Skip to content
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

add some accessibility features to web widgets #292

Merged
merged 2 commits into from
Jul 1, 2020

Conversation

TomPridham
Copy link
Contributor

@TomPridham TomPridham commented Apr 12, 2020

starts on #282, at least for web
adds some basic accessibility functionality to radio buttons, checkboxes, text inputs, and images.

@@ -118,8 +131,7 @@ where
vdom.schedule_render();
})
.finish(),
span(bump).children(vec![
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this span is necessary, and the other inputs don't have it. so i removed it for consistency

/// ```
#[derive(Debug)]
pub struct Image {
/// The image path
pub handle: Handle,

/// The alt text of the image
pub alt: String,
Copy link
Contributor Author

@TomPridham TomPridham Apr 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

images should always have alt text unless they are purely presentational, e.g. a background image. im not sure the best way to go about making this not necessary for those sorts of images, and having alt text be required feels like a good default

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could always be passed an empty string? Not sure how that works on screen readers and such though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could. i wasn't sure that implementing some sort of length requirement would be the correct thing to do since it would end up just being arbitrary. and i feel like most people ignore accessibility out of ignorance rather than malice, so having a reminder that alt text is required would be enough for most cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it seems like adding them as builder methods as @hecrj suggested will result in less empty alt tags since people will have to opt in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make alt text mandatory once we tackle accessibility in the native side of the ecosystem.

Comment on lines 57 to 59
/// - an optional placeholder
/// - a label describing the input
/// - an id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholders aren't replacements for labels. i made the placeholder optional so that people can decide whether they want one or not, but made label text required

@@ -67,7 +75,13 @@ impl<'a, Message> TextInput<'a, Message> {
{
Self {
_state: state,
placeholder: String::from(placeholder),
placeholder: if let Some(p) = placeholder {
Copy link
Contributor Author

@TomPridham TomPridham Apr 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if there is a better way to do this. i did it this way because i wasn't sure how to conditionally add an attribute. it seems like there should be, but i don't know enough about dodrio

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder.map(Into::into).unwrap_or_default() could work

.attr("for", text_input_id)
.children(vec![
text(text_input_label),
input(bump)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of this was whitespace because i nested the input inside of a label

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main challenge here is that we need to keep the intersection of iced_web and iced_native public APIs compatible. I believe it would be best to wait until we decide it's time to tackle accessibility for native platforms.

In the meantime, we could maybe add some of the accessibility information as additional builder methods, which would only be available when targetting Wasm.

@TomPridham
Copy link
Contributor Author

okay, that makes sense i'll rework this into builder methods

@TomPridham TomPridham force-pushed the feature/accessibility-web branch from a0cc6b1 to 8c4ea34 Compare April 22, 2020 04:20
@TomPridham TomPridham force-pushed the feature/accessibility-web branch from 8c4ea34 to 852d597 Compare April 22, 2020 04:35
@TomPridham
Copy link
Contributor Author

@hecrj, i updated this to use builder methods. i ended up just reverting the text input changes since it would require a lot more work to implement those changes

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have wrapped the id and name attributes in Option to explicitly avoid producing invalid HTML when values for these are not provided.

I think we can merge this! Thank you 🎉

@hecrj hecrj added the feature New feature or request label Jul 1, 2020
@hecrj hecrj added this to the 0.2.0 milestone Jul 1, 2020
@hecrj hecrj merged commit 08e13e0 into iced-rs:master Jul 1, 2020
@TomPridham TomPridham deleted the feature/accessibility-web branch July 2, 2020 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants