Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngHref): remove attribute when empty value instead of ignoring #6986

Closed
wants to merge 1 commit into from
Closed

fix(ngHref): remove attribute when empty value instead of ignoring #6986

wants to merge 1 commit into from

Conversation

shahata
Copy link
Contributor

@shahata shahata commented Apr 3, 2014

this will allow updating the values of ng-src, ng-srcset, ng-href back to empty state while preserving the intended behavior of not setting the attribute to an empty string to prevent behavior like trying to download the current page as an image or creating a link to the current page.

Fixes #2755

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6986)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@shahata
Copy link
Contributor Author

shahata commented Apr 3, 2014

The idea is that we remove the src/srcset/href attribute when value is empty. This works well on IE8 for both images and href. Please advise if I should write specific tests for msie.

@caitp
Copy link
Contributor

caitp commented Apr 4, 2014

Despite correctly removing the href attribute, I think it would be better to ensure that the original src attribute behaviour continues to behave as expected

@shahata
Copy link
Contributor Author

shahata commented Apr 4, 2014

@caitp I'm not sure I understand what you mean. Can you elaborate?

@caitp
Copy link
Contributor

caitp commented Apr 4, 2014

the original patch is meant to just avoid changing the src attribute if the interpolated value is blank. It may be better to change this so that it leaves a blank src value alone.

@shahata
Copy link
Contributor Author

shahata commented Apr 4, 2014

The only difference in my implementation is that when the source becomes blank I will remove the src attribute instead of leaving it with its current value. This means that the current image will disappear, while in the previous implementation it will remain the same.

The way I see it, the previous implementation wanted to avoid downloading of image with blank url, but solved it by creating a behavior which is not intuitive, while the new implementation solved the download of blank url with behavior that makes more sense.

I could change this to exclude src attribute so it will only happen if it is href or srcset, but I like it that the implementation is consistent. What do you think?

@caitp
Copy link
Contributor

caitp commented Apr 4, 2014

I believe the reason they don't want to change the URL is because they don't want to see FOUC-ish behaviour with the image beginning to load and then being removed, possibly multiple times

@shahata
Copy link
Contributor Author

shahata commented Apr 4, 2014

Not sure I understand when the value can change from non-blank to blank multiple times, but I pushed an amended commit which makes this work only for href. Looks good now?

@shahata shahata added cla: yes and removed cla: no labels Apr 4, 2014
@shahata shahata changed the title fix(booleanAttrs): remove attribute when empty value instead of ignoring fix(ngHref): remove attribute when empty value instead of ignoring Jun 17, 2014
@shahata
Copy link
Contributor Author

shahata commented Jun 17, 2014

@caitp - I've rebased this.

@Narretz Narretz added this to the Backlog milestone Jun 26, 2014
@hsablonniere
Copy link
Contributor

Where are we on this one ? I have the same problem :-(

@ajoslin
Copy link
Contributor

ajoslin commented Jul 8, 2014

Also encountering this problem in Ionic. Any updates? Anything that needs to be done to help it get merged?

@btford
Copy link
Contributor

btford commented Jul 23, 2014

This LGTM. @caitp shall we merge this?

@btford btford self-assigned this Jul 23, 2014
@caitp
Copy link
Contributor

caitp commented Jul 23, 2014

yes, sure. My source tree is a bit busy right now (promise refactoring), so it will be a while before I can check it in. You should do it!

@btford
Copy link
Contributor

btford commented Jul 23, 2014

✨ consider it done ✨

@btford btford modified the milestones: 1.3.0-beta.17, Backlog Jul 23, 2014
@ajoslin
Copy link
Contributor

ajoslin commented Jul 23, 2014

Awesome! Thanks.

@btford
Copy link
Contributor

btford commented Jul 23, 2014

Landed as 469ea33. Thanks @shahata!

@btford btford closed this Jul 23, 2014
@pholly
Copy link
Contributor

pholly commented Sep 10, 2014

Now anchor tags with href="" and ng-href="" remove the href attribute so browsers styles them differently (no pointer, for example in Chrome).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ng-href in <a> tag ignores empty value ""
8 participants