Tooltip/popover: data-bs-title and data-bs-content are reformatted or throw ("9.90" shows as "9.9", empty title throws)

Chiusa
#43,090 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

The data-API reads data-bs-title and data-bs-content through Manipulator.normalizeData, and the reporter places the fix in Tooltip._getConfig. Start by reproducing the cases in the reduced test case (9.90, empty title, after) with the standard init loop, then check the tooltip tests. Done means text attributes render exactly as written and a bad element no longer stops later tooltips from initializing. Settle the data-bs-content="null" behaviour change with maintainers before opening a pull request.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

backport-to-v5 bug confirmed js v5 v6
Prerequisites
Describe the issue

Tooltip and popover pass data-bs-title / data-bs-content through the data-API type conversion (Manipulator.normalizeData: numbers, "null", JSON.parse). For free text that changes or rejects what the author wrote. On the shipped 5.3.8 bundle and on main:

data-bs-title="9.90"   -> shows "9.9"
data-bs-title="2.0"    -> shows "2"
data-bs-title="1e3"    -> shows "1000"
data-bs-title='"quoted"' -> shows quoted (quotes removed)
data-bs-title=""       -> throws: Option "title" provided type "null" but expected type "(string|element|function)"
data-bs-title="null"   -> throws (same)
data-bs-title="[1,2]"  -> throws: provided type "array"

With the documented init loop ([...tooltipTriggerList].map(el => new bootstrap.Tooltip(el))), one throwing element also stops the tooltips after it from being initialized. An empty title from a template with a missing value is enough.

This looks like the remaining root cause of #41925 (booleans, fixed on main by #42548) and #22057 (numbers): title and content are text, so they could be read as written instead of normalized. I have a patch for main that does that in Tooltip._getConfig (with tests; the unit suite passes). One behaviour change to note: data-bs-content="null" would then show the text "null" instead of no content. Happy to open a PR against main and/or v5-dev if you want it.

Reproduction: <button data-bs-toggle="tooltip" data-bs-title="9.90">x</button> plus the standard init loop, then hover.

Disclosure: this was found, reproduced and patched by an AI agent (Claude Code), which ran the reproduction and tests quoted above. It has not been separately reviewed by a human.

Reduced test cases
<button type="button" class="btn" data-bs-toggle="tooltip" data-bs-title="9.90">price</button>
<button type="button" class="btn" data-bs-toggle="tooltip" data-bs-title="">empty</button>
<button type="button" class="btn" data-bs-toggle="tooltip" data-bs-title="after">after</button>
<script>
[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(el => new bootstrap.Tooltip(el))
</script>

Hover "price": shows 9.9. The second button throws, and "after" never gets a tooltip.

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

5.3.8 and main (v6.0.0-alpha.1)

Resolution by version

The v6 fix merged in #43113 for v6.0.0-alpha.2. Decimal strings and empty titles now keep their original text. This issue remains open for the v5 backport.

Lingua principale
MDX
Stelle
175k
Fork
78.7k
Merge medio
1g 5h
PR unite (30g)
94

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di twbs/bootstrap

Tutte le issue di twbs/bootstrap

Issue simili

Altre issue su Web Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.