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

How to avoid tooltips adding title & data-original-title attributes to DOM? #15359

Closed
ricardopolo opened this issue Dec 14, 2014 · 17 comments
Closed
Labels

Comments

@ricardopolo
Copy link

In Bootstrap Tooltip.js you can use HTML data attributes to define title of the tooltip

<button data-toggle="tooltip" data-placement="left" title="Tooltip on left">Button</button>

And then using Javascript intialize it

  $('[data-toggle="tooltip"]').tooltip()

We have a requirement where we need tooltips without modifiying the HTML (using data attributes). The tooltips are shown in the WYSIWYG Summernote editor and we don't want the user change them using the HTML editor.

So we initialize the tooltips using only Javascript. The title and the placement are specified using JS and not HTML.

  $('[data-toggle="tooltip"]').tooltip({ 'placement': 'left' , 'title' : 'Toolt on left'})

It works. Shows the tooltip as expected but it changes the HTML adding this attributes to the element

data-original-title="" title=""

Do you know why this happen? Do you know if we can avoid this feature and not modifiy the HTML after the tooltip is shown? If not, can we work in a PR to avoid this feature?

Thanks

@cvrebert cvrebert added the js label Dec 14, 2014
@cvrebert cvrebert changed the title Tooltip without modify DOM How to avoid tooltips adding title & data-original-title attributes to DOM? Dec 14, 2014
@cvrebert
Copy link
Collaborator

Seems like this might be a minor bug in the JS. Those attributes are being created due to the
typeof ($e.attr('data-original-title')) != 'string' check in

if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') {

When there's no data-original-title attribute, the .attr() results in undefined, which isn't a string, so that if is true, and the attribute creation code runs.
I'm not quite sure what the purpose of that check is. I'll try to do some code archaeology to find out.

@cvrebert
Copy link
Collaborator

That condition has been there since the original version of the tooltip plugin:
11721f3#diff-eb8af357ea1148bb9810f632978c69ffR112

@cvrebert
Copy link
Collaborator

The original Tipsy commit is jaz303/tipsy@43b7d62
(Tweaked to use jQuery in jaz303/tipsy@a663c5c)

@ricardopolo
Copy link
Author

@cvrebert based on the commit title I understand it was an IE6 compatibility fix.
Because boostrap don't support IE6 do you think we can remove this validation?

@cvrebert
Copy link
Collaborator

@ricardopolo Read the other commit. It's not strictly IE6-related.

@ricardopolo
Copy link
Author

@cvrebert you are right. I just created a PR asking for and optional attributed that does not change the DOM. Should we include the Dist files after grunt in the PR or only the source?

@cvrebert
Copy link
Collaborator

It's not necessary to include the dist files.

@augnustin
Copy link

This is #14769 I'd like to discuss, but it has been closed in favor of this one, while I'm unclear on how those two are related.

Basically, I don't understand why not doint what @peterblazejewicz suggested:

$btn.tooltip({
  title: function(){
    return $(this).attr('title');
  }
});

As far as I am concerned, I see the tooltip as a title improved (as the title attribute cannot really considered as a UI element as it is now). For this reason, I completely makes sense to read its value when displaying the title.

I guess I'll have to customize my own version of bootstrap again on this.

Thanks for any replies

@DumboJet
Copy link

+1
This always created problems for me.
I would really like JS to override the DOM and not change it in any way.
Apart form that, the title attribute has a specific job to do in HTML and taking it over for popover usage seems weird to me. I would understand it for tooltips, but not for popovers.

@MadLittleMods
Copy link

👍

1 similar comment
@akolechkin
Copy link

👍

@koxu1996
Copy link

koxu1996 commented Aug 8, 2016

I found solution here: http://stackoverflow.com/questions/27235776/can-i-still-use-the-title-attribute-on-bootstrap-popovers Add data-selector="true" and you will get original title working.

@webjohan
Copy link

webjohan commented Aug 22, 2016

Some WCAG validators doesn't like empty title attributes for links and reports errors.

Suggested improvement:

Let the show/hide functions handle the removing/clearing of the title attribute.

show:
(when setting attribute aria-describedby)
Remove title/set title empty

hide:
(when removing aria-describedby)
add the original title back to title-attribute

getTitle:
Don't set title=''

Is this a possible solution? Or is this totally unrelated and I should create a separate issue for this?

@mdo
Copy link
Member

mdo commented Sep 5, 2016

Bootstrap 3 is no longer being officially developed or supported.

All work has moved onto our next major release, v4. As such, this issue or pull request is being closed as a "won't fix." For additional help and support, we recommend utilizing our community resources. Thanks for your understanding, and see you on the other side of v4!

<3,
@mdo and team

@mdo mdo closed this as completed Sep 5, 2016
@1dd0
Copy link

1dd0 commented Jan 11, 2018

just set selector: true property to avoid using (and fixing/overeriding) target element title attribute

@jcmalek
Copy link

jcmalek commented Jan 6, 2021

This is still an issue in v4 of Bootstrap.

@cvrebert
Copy link
Collaborator

cvrebert commented Jan 6, 2021

Given the massive changes in v4, I'd advise opening a new issue for any current problems.

@twbs twbs locked and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.