Control button visibility, create custom presets, and enable multi-range selection
is_today_button_shown={false} ยท is_clear_button_shown={false} ยท is_apply_button_shown={false} ยท is_summary_shown={false}
Use attributes to show/hide built-in buttons (Today, Clear, Apply) and the range-mode days/nights summary.
// HTML attributes control built-in button visibility
<web-daterangepicker
is-today-button-shown="false"
is-clear-button-shown="false"
is-apply-button-shown="false">
</web-daterangepicker>
// Range mode: hide the days/nights summary block entirely
<web-daterangepicker selection-mode="range" is-summary-shown="false"></web-daterangepicker>
positioning_mode="modal"
Set positioning-mode="modal" to render the calendar as a centered overlay with a backdrop scrim instead of anchoring to the input. Helpful on small screens where multi-month layouts horizontally overflow.
// Centered overlay with backdrop โ close via Apply, Escape, or backdrop click
<web-daterangepicker selection-mode="range" positioning-mode="modal"></web-daterangepicker>
// Open programmatically
document.querySelector('#picker').isOpen = true;
// CSS variables for theming
--drp-modal-gap: 16px; /* viewport-edge gap */
--drp-modal-backdrop-bg: rgba(0,0,0,0.45); /* scrim color */
--drp-modal-transition: 150ms ease-out; /* fade timing */
auto_close="never | selection | apply"
Control when the calendar automatically closes with the auto-close attribute.
// Auto-close modes: 'never', 'selection' (default), 'apply'
<web-daterangepicker auto-close="never"></web-daterangepicker>
<web-daterangepicker auto-close="selection"></web-daterangepicker>
<web-daterangepicker auto-close="apply"></web-daterangepicker>
JS: el.actionButtons = [{ action: 'custom', text, onClick }]
Add custom buttons with preset date ranges using the JavaScript API.
const picker = document.querySelector('#preset-picker');
picker.actionButtons = [
{ action: 'custom', text: 'Last Week', onClick: ({ picker }) => {
const end = new Date(); const start = new Date();
start.setDate(end.getDate() - 7);
picker.selectedRanges = [{ start, end }]; // v2.0.0: start/end are read-only; set via selectedRanges
} },
{ action: 'custom', text: 'Next Week', onClick: ({ picker }) => { /* ... */ } },
{ action: 'custom', text: 'Next Month', onClick: ({ picker }) => { /* ... */ } },
{ action: 'clear', text: 'Clear' },
{ action: 'apply', text: 'Apply' }
];
selection_mode="multiple"
Allow selecting multiple individual dates or ranges programmatically.
// Multiple mode: click dates to toggle selection
<web-daterangepicker selection-mode="multiple"></web-daterangepicker>
// Get selected dates/ranges
const dates = picker.selectedDates; // Individual dates
const ranges = picker.selectedRanges; // Date ranges
JS prop: el.selectedRanges = [{ start, end }]
Control the picker from external buttons using reactive properties.
const picker = document.querySelector('#external-picker');
// Set a single range programmatically
picker.selectedRanges = [{ start: new Date('2025-01-01'), end: new Date('2025-01-31') }];
// Set multiple ranges (for multiple mode)
picker.selectedRanges = [
{ start: new Date('2025-01-01'), end: new Date('2025-01-07') },
{ start: new Date('2025-01-15'), end: new Date('2025-01-21') }
];
// Control calendar visibility
picker.isOpen = true;
picker.isOpen = false;
JS: isVisibleCallback: (ctx) => boolean ยท ctx.picker is the instance
Show/hide buttons based on picker state using the isVisibleCallback function.
const picker = document.querySelector('#conditional-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today' },
{ action: 'clear', text: 'Clear' },
{
action: 'apply', text: 'Apply',
// Only show Apply when both dates are selected
isVisibleCallback: ({ picker }) => picker.selectedStartDate && picker.selectedEndDate
}
];
JS: isDisabledCallback: (ctx) => boolean ยท ctx.picker is the instance
Enable/disable buttons dynamically based on picker state.
const picker = document.querySelector('#disabled-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today' },
{ action: 'clear', text: 'Clear',
isDisabledCallback: ({ picker }) => !picker.selectedStartDate && !picker.selectedEndDate },
{ action: 'apply', text: 'Apply',
isDisabledCallback: ({ picker }) => !picker.selectedStartDate || !picker.selectedEndDate }
];
JS: getTextCallback: (ctx) => string ยท ctx.picker is the instance
Change button text dynamically based on picker state.
const picker = document.querySelector('#text-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today' },
{ action: 'clear', text: 'Clear',
getTextCallback: ({ picker }) => picker.selectedStartDate ? 'Clear Selection' : 'Clear' },
{ action: 'apply', text: 'Apply',
getTextCallback: ({ picker }) => {
if (!picker.selectedStartDate || !picker.selectedEndDate) return 'Apply';
const days = Math.floor((picker.selectedEndDate - picker.selectedStartDate) / 86400000) + 1;
return `Apply (${days} day${days !== 1 ? 's' : ''})`;
} }
];
JS: getClassCallback: (ctx) => string | string[] ยท ctx.picker is the instance
Apply dynamic CSS classes to buttons based on picker state. Callback can return a single string or array of strings.
const picker = document.querySelector('#css-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today' },
{ action: 'clear', text: 'Clear', cssClass: 'clear-button',
getClassCallback: ({ picker }) => {
const classes = ['clear-button'];
if (picker.selectedStartDate || picker.selectedEndDate) classes.push('danger');
return classes;
} },
{ action: 'apply', text: 'Apply',
getClassCallback: ({ picker }) =>
(picker.selectedStartDate && picker.selectedEndDate) ? 'apply-ready' : 'apply-waiting' }
];
picker.customStylesCallback = () => `
.apply-ready { background: #10b981 !important; color: white !important; }
.apply-waiting { background: #d1d5db !important; color: #6b7280 !important; }
.danger { background: #ef4444 !important; color: white !important; }
`;
JS: getTooltipCallback: (ctx) => string ยท ctx.picker is the instance
Show contextual tooltips that change based on picker state. Hover over buttons to see dynamic tooltips.
const picker = document.querySelector('#tooltip-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today', tooltip: 'Jump to today',
getTooltipCallback: ({ picker }) => `Set to ${new Date().toLocaleDateString()}` },
{ action: 'clear', text: 'Clear', tooltip: 'Clear selection',
getTooltipCallback: ({ picker }) =>
(!picker.selectedStartDate && !picker.selectedEndDate)
? 'No selection to clear' : 'Clear the current date range' },
{ action: 'apply', text: 'Apply',
getTooltipCallback: ({ picker }) => {
if (!picker.selectedStartDate || !picker.selectedEndDate) return 'Select both start and end dates';
const days = Math.floor((picker.selectedEndDate - picker.selectedStartDate) / 86400000) + 1;
return `Apply ${days}-day range`;
} }
];
Demonstrates callback priority: *Callback functions override static properties when both are present.
isVisibleCallback โ isVisible โ trueisDisabledCallback โ isDisabled โ falsegetTextCallback โ text โ actiongetClassCallback โ cssClass โ ''getTooltipCallback โ tooltip โ ''
const picker = document.querySelector('#priority-picker');
picker.actionButtons = [
{ action: 'today', text: 'Today' },
{
action: 'clear',
text: 'Clear All', // Overridden by getTextCallback
cssClass: 'base-clear', // Overridden by getClassCallback
tooltip: 'Static tooltip', // Overridden by getTooltipCallback
isVisible: true, // Overridden by isVisibleCallback
isDisabled: false, // Overridden by isDisabledCallback
isVisibleCallback: ({ picker: p }) => p.selectedStartDate || p.selectedEndDate,
isDisabledCallback: ({ picker: p }) => !p.selectedStartDate && !p.selectedEndDate,
getTextCallback: ({ picker: p }) => (p.selectedStartDate || p.selectedEndDate) ? 'Clear Selection' : 'Clear All',
getClassCallback: ({ picker: p }) => (p.selectedStartDate || p.selectedEndDate) ? 'danger' : 'base-clear',
getTooltipCallback: ({ picker: p }) => (!p.selectedStartDate && !p.selectedEndDate) ? 'Nothing to clear' : 'Remove current selection'
}
];
Real-world examples of custom buttons for common business scenarios.
const picker = document.querySelector('#advanced-picker');
picker.actionButtons = [
{ action: 'custom', text: 'Last Business Week', tooltip: 'Select Monday-Friday of last week',
onClick: ({ picker }) => { /* set Mon-Fri of last week */ } },
{ action: 'custom', text: 'This Quarter', tooltip: 'Select current fiscal quarter',
onClick: ({ picker }) => { /* set current quarter */ } },
{ action: 'custom', text: 'Year to Date', tooltip: 'From Jan 1 to today',
onClick: ({ picker }) => { /* set Jan 1 โ today */ } },
{ action: 'custom', text: 'Rolling 90 Days', cssClass: 'rolling-period',
onClick: ({ picker }) => { /* set today-89 โ today */ } },
{ action: 'clear', text: 'Clear' },
{ action: 'apply', text: 'Apply' }
];
Add icons to buttons using HTML in the text property. Works with Font Awesome, Material Icons, or any icon library.
@import in customStylesCallback. The text property accepts HTML, allowing you to include <i> or <svg> elements.
const picker = document.querySelector('#icon-picker');
picker.actionButtons = [
{ action: 'today', text: '<i class="fa-solid fa-calendar-day"></i> Today', tooltip: 'Jump to today' },
{ action: 'clear', text: '<i class="fa-solid fa-circle-xmark"></i> Clear', cssClass: 'danger-icon' },
{ action: 'apply', text: '<i class="fa-solid fa-circle-check"></i> Apply', cssClass: 'success-icon' }
];
// Import Font Awesome into Shadow DOM and style buttons
picker.customStylesCallback = () => `
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css');
.drp__action { display: inline-flex; align-items: center; gap: 0.375rem; }
.success-icon { background: #10b981 !important; color: white !important; }
.danger-icon { background: #ef4444 !important; color: white !important; }
`;
Complete reference for all ActionButton interface properties.
| Property | Type | Required | Description |
|---|---|---|---|
action | 'today' | 'clear' | 'apply' | 'custom' | โ | Button action type. Use 'custom' for custom onClick handlers. |
text | string | โ | Button label (supports HTML for icons). |
onClick | (picker) => void | Custom click handler (required for action: 'custom'). |
| Property | Type | Description |
|---|---|---|
isVisibleCallback | (picker) => boolean | Dynamic visibility control based on picker state. |
isDisabledCallback | (picker) => boolean | Dynamic disabled state based on picker state. |
getTextCallback | (picker) => string | Dynamic button text based on picker state. |
getClassCallback | (picker) => string | string[] | Dynamic CSS classes (single string or array). |
getTooltipCallback | (picker) => string | Dynamic tooltip text based on picker state. |
When both static properties and callbacks are defined, callbacks take priority:
// Callback priority chain:
isVisibleCallback โ isVisible โ true
isDisabledCallback โ isDisabled โ false
getTextCallback โ text โ action
getClassCallback โ cssClass โ ''
getTooltipCallback โ tooltip โ ''
(pick a date anywhere on this page)