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

Fixes issues with placeholder state and url; adds error property. #44

Merged
merged 11 commits into from
Jan 13, 2016

Conversation

bicknellr
Copy link
Contributor

Fixes #16, #23, #30, #32, #33, #36.

@opus1269
Copy link
Contributor

I was testing this out and ran into a couple of problems:

The !! in the following binding doesn't work:

    <img id="img" role="none" hidden$="[[!!sizing]]">

I added back in the computed property to fix it:

    <img id="img" role="none" hidden$="[[_computeImageVisibility(sizing)]]">

The following CSS rules do not work:

    :host([sizing]) #backdrop {
      display: block;
    }

    :host([sizing]) #img {
      display: none;
    }

Pretty sure sizing needs to be an attribute for this to work. I added the reflectToAttribute to fix it:

      sizing: {
        type: String,
        reflectToAttribute: true,
        value: null
      },

I'm not sure if that's the right thing to do. Actually, with the hidden properties working, I'm not sure the various CSS rules changing the display attribute are even needed.

I can do a PR but I'm pretty new to this and don't know the procedure for a PR on another PR.

@bicknellr
Copy link
Contributor Author

Thanks for looking this over! IE10 doesn't pay attention to hidden and we still (mostly) support it so I'd say leave the CSS for that in for now; otherwise you're right, these rules should be redundant. Although this could be cleaner if replaced with:

[hidden] {
  display: none;
}

Also, yup, looks like !! doesn't work. :/ Going back to the computed property sounds good, if it's used in both places where !sizing was before for consistency. (The original name was a bit misleading too, maybe _computeImageHidden (or similar) would be more clear as it's returning whether or not the image is hidden rather than visible.)

Making a PR to a PR is really easy: every PR is just asking to merge one branch into another, so all you have to do is make a new request to merge your branch into this one (bicknellr/state) rather than master. When you're comparing changes from your branch and are about to make a PR you'll see two dropdown menus:
screen shot 2015-11-25 at 11 43 25
Here, you can specify which branch you would like to take changes from ('compare:') and which branch you'd like to merge those changes into ('base:', defaults to master).

If you want to submit a PR with some changes, I'd be glad to take them! (Otherwise, I can address the things you've pointed out once @cdata is ready to review.)

@opus1269
Copy link
Contributor

One more issue:

The EncodeURI on backdropImage and placeholder will be a breaking change for many users (including me :). It will double encode an already encoded URI used as input. If there isn't a really good reason for it, I would leave it out. If not, it probably needs to be clearly documented that raw input is expected.

@opus1269
Copy link
Contributor

I submited PR #48 to address the issues with hidden and display attributes. I left the EncodeURI as is.

@bicknellr
Copy link
Contributor Author

Yeah, you're right, expecting the input to be encoded beforehand is more reasonable (and is the behavior of the default img tag anyways).

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@bicknellr
Copy link
Contributor Author

@opus1269 I merged your changes and rebased on master - this seems to have confused @googlebot. Could you reply and let it know that you're ok contributing these changes?

@opus1269
Copy link
Contributor

I authored these commits.

On Mon, Nov 30, 2015 at 12:38 PM googlebot [email protected] wrote:

We found a Contributor License Agreement for you (the sender of this pull
request) and all commit authors, but as best as we can tell these commits
were authored by someone else. If that's the case, please add them to this
pull request and have them confirm that they're okay with these commits
being contributed to Google. If we're mistaken and you did author these
commits, just reply here to confirm.


Reply to this email directly or view it on GitHub
#44 (comment)
.

@bicknellr
Copy link
Contributor Author

Ok, well @googlebot seems to not be able to handle this, I've looked up that you signed it anyways so it should be alright.

},
img.onload = function() {
var resolvedSrc = Polymer.ResolveUrl.resolveUrl(this.src, this.ownerDocument.baseURI);
if (img.src !== resolvedSrc) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to refactor this into a protected method that lets you compare srcs. Something like..

if (this._matchesSrc(img.src)) return;

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll add this in.

<div id="placeholder" hidden$="[[_computePlaceholderVisibility(fade,loaded,preload)]]" class$="[[_computePlaceholderClassName(fade,loaded,preload)]]"></div>
<content></content>
<div id="sizedImgDiv" role="img" aria-label$="{{alt}}" hidden$="[[_computeBackdropHidden(sizing)]]"></div>
<img id="img" alt$="{{alt}}" hidden$="[[_computeImgHidden(sizing)]]">
Copy link

Choose a reason for hiding this comment

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

This looks really nice.

However, one thing I hadn't considered is that this means the default case will be that this will be

<img alt="" src=...>

This means that unless the user specifies an alt attribute, the image will be hidden from screen readers (won't show up at all, as if it's not there to begin with).
Is there some way to set the default value to be null and judiciously add this attribute only if the alt attribute on the host is non-null?

Similarly, if the user does set alt="" on the host, #sizedImagDiv should probably be aria-hidden, to get the same effect.

(For extra credit, it would be great to set a placeholder aria-label on #sizedImgDiv in that case. For <img> elements, screen readers do the job on their own if no alt attribute is provided, but in this case it won't have enough information to do that since this isn't an <img>. The usual fallback is the filename part of the src.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So aria-label="" doesn't hide an element from screen readers like alt="" would?

Copy link

Choose a reason for hiding this comment

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

Nope - with ARIA everything needs to be explicit. With native attributes there's a bunch of implicit stuff that goes on that you just kinda ... need to memorise. :\

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, updated again. I wrote some tests too but they're really implementation dependent. Is there any way to programmatically inspect the accessibility tree?

Copy link

Choose a reason for hiding this comment

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

You can't directly programmatically inspect the accessibility tree just yet - there are a couple of experimental APIs around but not really in any usable state for your purposes.

The Accessibility Developer Tools does have some utils for trying to work out the computed name and role of a particular element:

https://github.com/GoogleChrome/accessibility-developer-tools/blob/master/src/js/AccessibilityUtils.js#L626
https://github.com/GoogleChrome/accessibility-developer-tools/blob/master/src/js/Properties.js#L236

Obviously in this case you'd still need to look at the child nodes inside shadow DOM, though.

Copy link

Choose a reason for hiding this comment

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

Also, this looks really great now! I love all the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nifty; @cdata can you take a look again?

reflectToAttribute: true
},

_imgDivARIALabel: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this isn't meant to be set from the outside. It's just part of a bug work-around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(gone now anyways)

@bicknellr
Copy link
Contributor Author

@cdata one more time?

@kevin-wise
Copy link

@cdata Is there any chance this could get merged soon? We are waiting on this for #33.

@abdonrd
Copy link
Member

abdonrd commented Jan 7, 2016

+1

2 similar comments
@BartKoppelmans
Copy link

+1

@opus1269
Copy link
Contributor

👍

_computeRequiresPreload: function() {
return this.preload && !this.loaded;
var pathComponents = (new URL(this._resolveSrc(this.src))).pathname.split("/");
return pathComponents[pathComponents.length - 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Fancy 💎

@cdata
Copy link
Contributor

cdata commented Jan 13, 2016

Small details, otherwise LGTM 👍

bicknellr added a commit that referenced this pull request Jan 13, 2016
Fixes issues with placeholder state and url; adds error property.
@bicknellr bicknellr merged commit c95d43d into master Jan 13, 2016
@bicknellr bicknellr deleted the bicknellr/state branch January 13, 2016 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants