Main content ah kal rawh Docs navigation ah kal rawh
Check
in English

Popovers te an ni

Documentation leh Bootstrap popovers, iOS-a hmuh ang chi, i site-a element eng pawha dah belh dan tur.

A tlangpuiin

Popover plugin hman huna hriat tur awmte:

  • Popovers te hian positioning atan third party library Popper an ring tlat a ni. , hmain popper.min.js i dah tel tur a ni a , a nih loh leh Popper awmna bootstrap.jshmang tur a ni.bootstrap.bundle.min.js
  • Popovers hian popover plugin hi dependency atan a mamawh a ni.
  • Popovers hi performance avanga opt-in a nih avangin nangmah ngeiin i initialize tur a ni .
  • Zero-length titleleh contentvalue te hian popover a lantir ngai lovang.
  • container: 'body'Component complex zawk (kan input group, button group, etc)-a rendering problem awm loh nan specify rawh .
  • Hidden elements-a popovers trigger hian hna a thawk dawn lo.
  • Popovers for .disabledor disabledelements te chu wrapper element ah trigger tur a ni.
  • Line hrang hranga wrap anchor atanga trigger a nih chuan popovers te chu anchor zawng zawng zau zawng inkar ah centered a ni ang. Hetiang thiltih hi pumpelh nan .text-nowrapi s hmangin hmang rawh .<a>
  • Popovers te hi DOM atanga an element inmil te lakchhuah a nih hmain thup a ngai a ni.
  • Shadow DOM chhunga element awm vangin popovers a trigger thei a ni.
Default-ah chuan he component hian built-in content sanitizer a hmang a, chu chuan HTML element chiang taka phal loh zawng zawng a strip chhuak vek a ni. Kan JavaScript documentation-a sanitizer section-ah hian a chipchiar zawkin en rawh .
He component hian animation effect hi prefers-reduced-motionmedia query ah a innghat a ni. Kan accessibility documentation a reduced motion tih hi en la .

Entirna thenkhat nen popovers te hnathawh dan hriat duh chuan chhiar chhunzawm zel ang che.

Entirna te

Popovers te chu enable rawh

A chunga kan sawi tawh ang khan popovers te hi i hman theih hmain i initialize hmasa phawt tur a ni. Page pakhata popover zawng zawng initialize dan pakhat chu an data-bs-toggleattribute hmanga thlan chhuah a ni ang, hetiang hian:

const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]')
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl))

Live demo a ni ang

A hnuaia live popover hi render turin a chunga snippet ang chiah hian JavaScript kan hmang a. Title te chu via set a ni a data-bs-title, body content chu via set a data-bs-contentni bawk.

Zalen takin i HTML ah titleemaw hmang thei ang che. data-bs-titleA hman hunah chuan Popper chuan element render a nih hunah titleautomatic in a thlak ang .data-bs-title
html tih a ni
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>

Kawng pali

Thil pali a awm a: chunglam, dinglam, hnuai lam, leh veilam. RTL a Bootstrap hman hian directions a mirror thin. data-bs-placementDirection thlak turin set rawh .

html tih a ni
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Top popover">
  Popover on top
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="right" data-bs-content="Right popover">
  Popover on right
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content="Bottom popover">
  Popover on bottom
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="left" data-bs-content="Left popover">
  Popover on left
</button>

Chindancontainer

Popover tibuaitu parent element-a style thenkhat i neih chuan, containerchu element chhungah chuan popover-a HTML chu a lang zawk theih nan custom i dah duh ang. Hei hi responsive table, input group leh a dangteah a awm fo thin.

const popover = new bootstrap.Popover('.example-popover', {
  container: 'body'
})

Explicit custom set duhna tur dinhmun dang chu containerpopovers inside a modal dialog , popover ngei pawh modal-a append a nih theih nan. Hei hi interactive elements awmna popovers tan a pawimawh hle – modal dialogs hian focus a trap ang a, chuvangin popover hi modal-a child element a nih loh chuan users te chuan heng interactive elements te hi an focus thei dawn lo va, an activate thei dawn lo bawk.

const popover = new bootstrap.Popover('.example-popover', {
  container: '.modal-body'
})

Custom popovers te pawh a awm

v5.2.0 ah dah belh a ni

CSS variable hmangin popovers awm dan tur i siam danglam thei bawk . Kan custom appearance scope turin custom class with kan set a, data-bs-custom-class="custom-popover"chu chu local CSS variable thenkhat override nan kan hmang a.

.custom-popover {
  --bs-popover-max-width: 200px;
  --bs-popover-border-color: var(--bs-primary);
  --bs-popover-header-bg: var(--bs-primary);
  --bs-popover-header-color: var(--bs-white);
  --bs-popover-body-padding-x: 1rem;
  --bs-popover-body-padding-y: .5rem;
}
html tih a ni
<button type="button" class="btn btn-secondary"
        data-bs-toggle="popover" data-bs-placement="right"
        data-bs-custom-class="custom-popover"
        data-bs-title="Custom popover"
        data-bs-content="This popover is themed via CSS variables.">
  Custom popover
</button>

A hnuaia click leh hunah dismiss rawh

focusUser-in toggle element aia element dang a click leh hunah popovers chu dismiss turin trigger hmang ang che .

Dismiss-on-next-click atan markup bik a ngai

Cross-browser leh cross-platform behavior dik tak neih theih nan tag ni lovin tag i hmang tur a ni <a>a , attribute <button>pawh i dah tel tur a ni.tabindex

html tih a ni
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
const popover = new bootstrap.Popover('.popover-dismiss', {
  trigger: 'focus'
})

Elements tihtawp a ni

Attribute nei element te disabledhi interactive an ni lo a, chu chu user te chuan popover (or tooltip) trigger turin hover emaw click emaw an ti thei lo tihna a ni. <div>Workaround angin, wrapper emaw <span>, ideally made keyboard-focusable hmanga siam popover atanga trigger i duh ang tabindex="0".

Disabled popover triggers tan chuan i duh zawk thei bawk a, chutiang bawkin popover chu i hmangtute hnenah disabled element clickdata-bs-trigger="hover focus" an beisei loh avangin visual feedback nghal ang maia lang turin i duh thei bawk.

html tih a ni
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-content="Disabled popover">
  <button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>

CSS a ni

Variables te pawh a awm

v5.2.0 ah dah belh a ni

Bootstrap-in CSS variables approach a kalpui mek zingah hian popovers te hian local CSS variables on hmangin .popoverreal-time customization tihchangtlun nan an hmang ta a ni. CSS variable hrang hrangte tana value te hi Sass hmanga set a nih avangin Sass customization pawh a la support reng bawk.

  --#{$prefix}popover-zindex: #{$zindex-popover};
  --#{$prefix}popover-max-width: #{$popover-max-width};
  @include rfs($popover-font-size, --#{$prefix}popover-font-size);
  --#{$prefix}popover-bg: #{$popover-bg};
  --#{$prefix}popover-border-width: #{$popover-border-width};
  --#{$prefix}popover-border-color: #{$popover-border-color};
  --#{$prefix}popover-border-radius: #{$popover-border-radius};
  --#{$prefix}popover-inner-border-radius: #{$popover-inner-border-radius};
  --#{$prefix}popover-box-shadow: #{$popover-box-shadow};
  --#{$prefix}popover-header-padding-x: #{$popover-header-padding-x};
  --#{$prefix}popover-header-padding-y: #{$popover-header-padding-y};
  @include rfs($popover-header-font-size, --#{$prefix}popover-header-font-size);
  --#{$prefix}popover-header-color: #{$popover-header-color};
  --#{$prefix}popover-header-bg: #{$popover-header-bg};
  --#{$prefix}popover-body-padding-x: #{$popover-body-padding-x};
  --#{$prefix}popover-body-padding-y: #{$popover-body-padding-y};
  --#{$prefix}popover-body-color: #{$popover-body-color};
  --#{$prefix}popover-arrow-width: #{$popover-arrow-width};
  --#{$prefix}popover-arrow-height: #{$popover-arrow-height};
  --#{$prefix}popover-arrow-border: var(--#{$prefix}popover-border-color);
  

Sass a danglam thei

$popover-font-size:                 $font-size-sm;
$popover-bg:                        $white;
$popover-max-width:                 276px;
$popover-border-width:              $border-width;
$popover-border-color:              var(--#{$prefix}border-color-translucent);
$popover-border-radius:             $border-radius-lg;
$popover-inner-border-radius:       subtract($popover-border-radius, $popover-border-width);
$popover-box-shadow:                $box-shadow;

$popover-header-font-size:          $font-size-base;
$popover-header-bg:                 shade-color($popover-bg, 6%);
$popover-header-color:              $headings-color;
$popover-header-padding-y:          .5rem;
$popover-header-padding-x:          $spacer;

$popover-body-color:                $body-color;
$popover-body-padding-y:            $spacer;
$popover-body-padding-x:            $spacer;

$popover-arrow-width:               1rem;
$popover-arrow-height:              .5rem;

Hman dan tur

JavaScript hmangin popovers te chu enable rawh:

const exampleEl = document.getElementById('example')
const popover = new bootstrap.Popover(exampleEl, options)

Keyboard leh assistive technology hmangtute tan popovers hnathawh tir

Keyboard hmangtute’n i popovers an activate theih nan, HTML elements, hmanlai keyboard-focusable leh interactive (link emaw form control ang chi)-ah chauh i dah tur a ni. Attribute dah belh hian arbitrary HTML elements ( <span>s ang chi) chu focusable-a siam theih ni mah se tabindex="0", hei hian keyboard hmangtute tan non-interactive element-a tab stop tibuaitu leh buaithlak tak tak a dah belh dawn a, tunah hian assistive technology tam zawk chuan hetiang dinhmunah hian popover-a thu awmte hi an puang lo . hoverTin, i popovers te tan trigger atan chauh rinchhan suh , hei hian keyboard hmangtute tan trigger theih loh a siam dawn avangin.

Popovers-ah hian htmloption hmangin rich, structured HTML i dah thei a, mahse, content tam lutuk dah loh turin kan fuih tak zet che a ni. Tuna popovers hnathawh dan chu, vawi khat a lan hnuah, an content chu aria-describedbyattribute nei trigger element nen an inzawm tlat a ni. Chumi avang chuan popover-a thu awm zawng zawng chu assistive technology hmangtute hnenah stream rei tak, tihtawp loh pakhat anga puan a ni ang.

Tin, i popover-ah hian interactive controls (form elements emaw links ang chi) te pawh telh theih a nih laiin (heng elements te hi allowListof allowed attributes leh tags-ah te dah belhin), tunah chuan popover hian keyboard focus order a enkawl lo tih hre reng ang che. Keyboard hmangtuin popover a hawn chuan triggering element-ah focus a awm reng a, popover hian document structure-a trigger a zawm nghal loh tlangpui avangin hmalam pan/pressing tih theihna tur guarantee a awm loTABkeyboard hmangtu pakhat chu popover chhungah ngei a hruai lut ang. A tawi zawngin, popover-a interactive controls dah mai mai chuan heng control-te hi keyboard hmangtu leh assistive technology hmangtute tan chuan thlen theih loh/hman theih loh a nih a rinawm a, a tlem berah chuan overall focus order chu a dik lo hle mai thei bawk. Heng hunah hian modal dialog hman ai chuan ngaihtuah zawk ang che.

Thil thlan theih a ni

Options chu data attribute emaw JavaScript hmanga pass theih a nih avangin option hming chu data-bs-, ah hian i append thei ang data-bs-animation="{value}". Data attribute hmanga options pass dawnin option hming case type chu “ camelCase ” atanga “ kebab-case ” ah thlak ngei ngei tur a ni. Entirnan, data-bs-custom-class="beautifier"tih aiah hmang data-bs-customClass="beautifier"rawh.

Bootstrap 5.2.0 atang khan component zawng zawng hian experimental reserved data attribute an support data-bs-configa, chu chuan JSON string angin component configuration awlsam tak a dah thei a ni. Element pakhatin data-bs-config='{"delay":0, "title":123}'leh data-bs-title="456"attribute a neih chuan a tawp ber titlevalue chu a ni ang a 456, data attribute hrang hrangte chuan , a value pekte chu a override ang data-bs-config. Chu bakah, data attribute awmsa te hian JSON value te chu data-bs-delay='{"show":0,"hide":150}'.

Security avang hian sanitize, sanitizeFn, leh allowListoption te hi data attribute hmangin supply theih a ni lo tih hre reng ang che.
Hming Lampang Hlawhchhamna Hrilhfiahna
allowList thil Default value a ni Object ah chuan attribute leh tag phalsak te a awm.
animation boolean a ni true Popover ah hian CSS fade transition hmangin apply rawh.
boundary string, element tih a ni 'clippingParents' Popper-a overflow constraint boundary (Popper-a preventOverflow modifier-ah chauh hman tur a ni). Default-ah chuan 'clippingParents'HTMLElement reference a ni a, a pawm thei bawk (JavaScript hmang chauh). Hriat belh duh chuan Popper-a detectOverflow docs en rawh.
container string, element, dik lo tihna a ni false Popover chu element bik pakhatah a append thin. Entirnan: container: 'body'. He option hi a bik takin a tangkai hle a, triggering element bulah document flow-ah popover chu dah theih a ni - chu chuan window resize laiin popover chu triggering element atanga hla takah a float loh nan a veng ang.
content string, element, hnathawh dan te '' data-bs-contentAttribute a awm loh chuan default content value a ni. Function pek a nih chuan a thisreference set chu popover attached element-ah dahin a ko ang.
customClass string, hnathawh dan '' Popover a lan hunah class te dah belh rawh. Template-a class tarlan zawng zawng bakah heng class te hi dah belh a ni ang tih hre reng ang che. Class tam tak dah belh tur chuan space hmangin then rawh: 'class-1 class-2'. Class hming dang awmna string pakhata rawn pe chhuak tur function pawh i pass thei bawk.
delay number, thil awm 0 Popover (ms) entir leh thup hun sawn hlat—manual trigger type-ah chuan a hman theih loh. Number supply a nih chuan hide/show pahnih ah delay a awm vek a ni. Thil awm dan chu: delay: { "show": 500, "hide": 100 }.
fallbackPlacements string, array tih a ni ['top', 'right', 'bottom', 'left'] Fallback placement te chu array-a placement list (a duh dan angin) pein define rawh. Hriat belh duh chuan Popper-a behavior docs en rawh.
html boolean a ni false Popover ah HTML phalsak rawh. A dik a nih chuan popover’s a HTML tag te chu popover titleah a render ang. False a nih chuan innerTextproperty hmangin DOM ah content dah a ni ang. XSS attack i ngaihtuah chuan text hmang rawh.
offset number, string, hnathawh dan te [0, 0] Popover chu a target nena khaikhin chuan offset a ni. Data attribute-ah string pakhat chu comma separated value hmangin i pass thei a, chu chu: data-bs-offset="10,20". Offset hriat nan function hman a nih chuan a argument hmasa ber atan popper placement, reference leh popper rects te awmna object hmangin koh a ni. Triggering element DOM node chu argument pahnihna atan pass a ni. Function hian number pahnih nei array a rawn pe chhuak tur a ni: skidding , distance . Hriat belh duh chuan Popper-a offset docs en rawh.
placement string, hnathawh dan 'top' Popover dah dan: auto, chunglam, hnuai lam, veilam, dinglam. A autotarlan hunah chuan popover chu dynamically in a reorient ang. Function pakhat hmanga placement hriat chian a nih chuan popover DOM node chu a argument hmasa ber atan leh triggering element DOM node chu a pahnihna atan hmangin koh a ni. Context chu thispopover instance ah dah a ni.
popperConfig null, thil, hnathawh null Bootstrap-a Popper config default thlak tur chuan Popper-a configuration en rawh . Popper configuration siamna atana function hman a nih chuan Bootstrap-a default Popper configuration awmna object hmangin koh a ni. Default chu i configuration nen hman leh merge turin a pui che a ni. Function hian Popper tan configuration object a rawn pe chhuak tur a ni.
sanitize boolean a ni true Sanitization hi enable emaw disable emaw theih a ni. Activated a nih chuan 'template', 'content'leh 'title'options te chu sanitized a ni ang.
sanitizeFn null, hnathawh null Hetah hian mahni sanitize function i supply thei ang. Sanitization tih nan library bik hman i duh chuan hei hi a tangkai thei hle.
selector string, dik lo false Selector pek a nih chuan popover objects chu target tarlan te hnenah delegate a ni ang. jQuery.onPractice-ah chuan hei hi dynamically added DOM elements ( support)-a popovers hmanna atan pawh hman a ni. He issue leh entîrna thu hriat theihna en rawh .
template hrui '<div class="popover" role="popover"><div class="popover-arrow"></div><div class="popover-inner"></div></div>' Popover siam huna hman tur HTML base rawh. Popover's titlechu inject a ni ang a, .popover-inner. .popover-arrowpopover-a thal a lo ni ta a ni. Wrapper element pawn lam ber chuan .popoverclass leh role="popover".
title string, element, hnathawh dan te '' titleAttribute a awm loh chuan title value default a ni. Function pek a nih chuan a thisreference set chu popover attached element-ah dahin a ko ang.
trigger hrui 'hover focus' Popover a tihchhuah dan: click, hover, focus, manual. Trigger tam tak i pass thei a; space hmangin then hran rawh. 'manual'popover chu programmatic-a trigger a nih tur thu a tarlang a .popover('show'), , .popover('hide')leh .popover('toggle')methods; he value hi trigger dang nen a inzawm thei lo. 'hover'a mah chauhin keyboard hmanga trigger theih loh popovers a thlen ang a, keyboard hmangtute tana information inang thehdarh dan dang a awm chauhvin hman tur a ni.

Mimal popovers te tan data attribute te

Mimal popover-te tana duhthlan tur chu a dangin data attribute hmanga tarlan theih a ni a, a chunga kan sawi tawh ang khan.

Function hman dan nenpopperConfig

const popover = new bootstrap.Popover(element, {
  popperConfig(defaultBsPopperConfig) {
    // const newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Thiltih dan tur

Asynchronous method leh inthlak danglamna te

API method zawng zawng hi asynchronous a ni a , transition a tan vek a ni . Transition an tan veleh mahse a tawp hmain call tu hnenah an kir leh thin . Chu bakah, transitioning component-a method call chu ngaihthah a ni ang .

Hriat belh duh chuan kan JavaScript documentation en rawh .

Tihdan Hrilhfiahna
disable Element pakhat popover lantir theihna tur a paih chhuak. Popover hi re-enable a nih chauhvin a lantir theih dawn a ni.
dispose Element pakhat popover chu a thup a, a tichhe bawk (DOM element-a data dahkhawmte a paih chhuak). Delegation hmanga siam Popovers ( option hmanga siamselector ) te chu descendant trigger element-ah pakhat zel tihchhiat theih a ni lo.
enable Element pakhat popover chu a lantir theihna a pe. Popovers hi default in enable a ni.
getInstance Static method hmanga DOM element nena inzawm popover instance hmuh theihna tur.
getOrCreateInstance Static method hmangin DOM element nena inzawm popover instance chu i hmu thei a, a nih loh leh initialized a nih loh chuan a thar siam theih a ni bawk.
hide Element pakhat popover a thup. Popover chu thup tak tak a nih hmain (chu chu hidden.bs.popoverthilthleng a thlen hma) call tu hnenah a kir leh thin. Hei hi popover “manual” triggering anga ngaih a ni.
setContent Popover-a a initialization hnua a content thlak danglam dan tur a pe.
show Element pakhat popover a nihzia a pholang. Popover a lan tak tak hmain (chu chu shown.bs.popoverevent a thlen hmain) caller hnenah a kir leh thin. Hei hi popover “manual” triggering anga ngaih a ni. Popovers title leh content zero-length pahnih nei te chu an lang ngai lo.
toggle Element pakhat popover a toggle thin. Popover a lan tak tak emaw a thup hma emaw (chu chu shown.bs.popoveror hidden.bs.popoverevent a thlen hma) caller hnenah a kir leh thin. Hei hi popover “manual” triggering anga ngaih a ni.
toggleEnabled Element pakhat popover lantir emaw thup emaw theihna tur a toggles.
update Element pakhat popover awmna hmun a update thin.
// getOrCreateInstance example
const popover = bootstrap.Popover.getOrCreateInstance('#example') // Returns a Bootstrap popover instance

// setContent example
myPopover.setContent({
  '.popover-header': 'another title',
  '.popover-body': 'another content'
})
setContentMethod chuan argument a pawm a object, chutah chuan property-key tin chu popover template chhunga selector dik tak a ni a string, a kaihhnawih property-value tinte chu string| element| function| null

Thil thlengte

Hunbik Hrilhfiahna
hide.bs.popover hideHe event hi instance method koh a nih chuan a fire nghal a ni.
hidden.bs.popover He event hi popover chu user hnen atanga thup a nih zawh chuan fired a ni (CSS transitions zawh hun a nghak ang).
inserted.bs.popover show.bs.popoverHe event hi DOM-a popover template dah a nih hunah event zawhah fired a ni.
show.bs.popover showHe event hi instance method kan koh chuan a fire nghal vek a ni.
shown.bs.popover He event hi popover chu user hmuh theiha siam a nih hunah fire a ni (CSS transitions zawh hun a nghak ang).
const myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', () => {
  // do something...
})