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

Docs: how to use paper-button as a link #35

Closed
robdodson opened this issue Jul 24, 2015 · 22 comments
Closed

Docs: how to use paper-button as a link #35

robdodson opened this issue Jul 24, 2015 · 22 comments

Comments

@robdodson
Copy link
Contributor

Element doc should include an example of wrapping the button in an anchor so it can be used as a link.

@SayChunKim
Copy link

+1

1 similar comment
@gulyasfeccferenc
Copy link

+1

@ebidel
Copy link
Contributor

ebidel commented Jul 31, 2015

Here's one way:

<paper-button onclick="addNewFeature(this)"></paper-button>

function addNewFeature(el) {
  // Wait for ripple to finish.
  el.addEventListener('transitionend', function(e) {
    location.href = '/admin/features/new';
  });
}```

You could also use a declarative `<a>` and prevent the click, wait for the ripple to finish, and then do the redirect.

@ebidel ebidel changed the title Document how to use paper-button as a link Docs: how to use paper-button as a link Jul 31, 2015
@robdodson
Copy link
Contributor Author

Or use the noink attr if you aren't a fan of the ripple

@kaycebasques
Copy link

👍 AKA +1

@abdonrd
Copy link
Member

abdonrd commented Dec 8, 2015

With the @ebidel way, we need to write a javascript function...

<paper-button onclick="addNewFeature(this)"></paper-button>
function addNewFeature(el) {
  // Wait for ripple to finish.
  el.addEventListener('transitionend', function(e) {
    location.href = '/admin/features/new';
  });
}

And if we use a declarative <a>, we lost the ripple and maybe it is an ugly code:

<a href="https://www.polymer-project.org">
    <paper-button>Polymer website</paper-button>
</a>

We can have something like this?

<paper-button href="https://www.polymer-project.org">Polymer website</paper-button>

@ebidel
Copy link
Contributor

ebidel commented Dec 8, 2015

I don't think href makes sense on paper-button, but it would be nice if paper-button knew it had a anchor children and had a feature that de-janked the ripple for you.

@abdonrd
Copy link
Member

abdonrd commented Dec 8, 2015

@ebidel like this?

<paper-button>
    <a href="https://www.polymer-project.org">Polymer website</a>
</paper-button>

@ebidel
Copy link
Contributor

ebidel commented Dec 8, 2015

Yes. It would JustWork:registered:

@abdonrd
Copy link
Member

abdonrd commented Dec 8, 2015

@ebidel and we have the same problem with the paper-icon-button.
It would be something like this? An empty <a> is strange.

<paper-icon-button icon="polymer">
    <a href="https://www.polymer-project.org"></a>
</paper-icon-button>

@abdonrd
Copy link
Member

abdonrd commented Dec 16, 2015

@robdodson @ebidel do you have any news about this?

We have the same "problem" with the paper-icon-button.

@MeTaNoV
Copy link

MeTaNoV commented Dec 16, 2015

/sub

@cdata
Copy link
Contributor

cdata commented Dec 16, 2015

After thinking about this for a bit, I believe the ideal we should strive for is this form:

<a href="https://www.polymer-project.org">
  <paper-button>Polymer website</paper-button>
</a>

However, there may be problems with this form (e.g., a parent expects a specific kind of child, so wrapping is not an option). Are there any known conditions that you guys have run into where this would not work?

And if we use a declarative , we lost the ripple

I tested this and the ripple seems to work fine in this condition.

@cdata
Copy link
Contributor

cdata commented Dec 16, 2015

@robdodson @ebidel @abdonrd ^

@robdodson
Copy link
Contributor Author

That looks fine to me. I would maybe put noink on the button to get rid of
the ripple so it doesn't jank the page.
On Dec 16, 2015 3:15 PM, "Christopher Joel" notifications@github.com
wrote:

@robdodson https://github.com/robdodson @ebidel
https://github.com/ebidel @abdonrd https://github.com/abdonrd ^


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

@abdonrd
Copy link
Member

abdonrd commented Dec 19, 2015

Thanks @cdata!

I can you show an use of case when we have problems: http://jsbin.com/kuyisinara
We have a small problem, easily solved with CSS.
But try to use the tab key and see the focus behavior. :(

The solution would be to add the tabindex="-1" to the as?

@keanulee
Copy link
Contributor

Added an example of this in #91. I decided to leave out the noink attribute since it's nice to see the ripple effect when the user mousedowns (navigation doesn't occur until mouseup).

@abdonrd
Copy link
Member

abdonrd commented Jan 21, 2016

@keanulee check the behavior with focus. :/

First tab:
screen shot 2016-01-21 at 20 17 42

Second tab:
screen shot 2016-01-21 at 20 17 50

@keanulee
Copy link
Contributor

Ah yes, that is an issue. Easy way to fix this is to add tabindex="-1" to the <a> tag. <paper-button> would still be able to receive focus, and you can still navigate. I'll add this to #91. Thanks @abdonrd

@abdonrd
Copy link
Member

abdonrd commented Jan 21, 2016

Nice @keanulee! Your welcome!

@keanulee
Copy link
Contributor

Example has been added in #91

@abdonrd
Copy link
Member

abdonrd commented Jan 25, 2016

@keanulee It would be great if you add another example waiting to finish the ripple effect before opening the link. 😊

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

No branches or pull requests

9 participants