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

feat: add live alert type selection #41201

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion site/assets/js/partials/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,22 @@
const alertPlaceholder = document.getElementById('liveAlertPlaceholder')
const appendAlert = (message, type) => {
const wrapper = document.createElement('div')
wrapper.innerHTML = [
`<div class="alert alert-${type} alert-dismissible" role="alert">`,
` <div>${message}</div>`,
' <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',
'</div>'
].join('')

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

alertPlaceholder.append(wrapper)
}

const alertTrigger = document.getElementById('liveAlertBtn')
const selectAlertType = document.getElementById('liveAlertType')
if (alertTrigger) {
alertTrigger.addEventListener('click', () => {
appendAlert('Nice, you triggered this alert message!', 'success')
const alertType = selectAlertType.value
appendAlert('Nice, you triggered this alert message!', alertType)
})
}
// js-docs-end live-alert
Expand Down
12 changes: 12 additions & 0 deletions site/content/docs/5.3/components/alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ Click the button below to show an alert (hidden with inline styles to start), th

{{< example stackblitz_add_js="true" >}}
<div id="liveAlertPlaceholder"></div>
<div class="d-flex align-items-center gap-2">
<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
<select id="liveAlertType" class="form-select w-auto d-inline-block">
<option value="primary">Primary</option>
<option value="secondary">Secondary</option>
<option value="success" selected>Success</option>
<option value="danger">Danger</option>
<option value="warning">Warning</option>
<option value="info">Info</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</div>
{{< /example >}}

We use the following JavaScript to trigger our live alert demo:
Expand Down