โ† Back to Examples

๐ŸŽฏ Button Configuration

Control button visibility, create custom presets, and enable multi-range selection

1. Button & Summary Visibility Control

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.

is-today-button-shown="false" is-clear-button-shown="false" is-apply-button-shown="false"
is-today-button-shown="false" is-apply-button-shown="false"
auto-close="apply" is-today-button-shown="false" is-clear-button-shown="false"
is-summary-shown="false" โ€” hides the days/nights count line entirely (no empty-div jump)
// 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>

1b. Modal Display Mode (centered overlay)

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.

positioning-mode="modal" โ€” click input or button to open
visible-months-count="3" โ€” would overflow horizontally on mobile in floating mode; in modal it fits and scrolls vertically
month-layout="grid" grid-rows="2" grid-columns="3" โ€” six months in a centered grid
positioning-mode="floating" mobile-modal-breakpoint="768px" mobile-modal-min-height="500px" โ€” floating when there's enough room, modal when viewport is too narrow OR too short (resize the window to test)
// 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 */

2. Auto-Close Behavior

auto_close="never | selection | apply"

Control when the calendar automatically closes with the auto-close attribute.

Calendar NEVER auto-closes, not even with Apply button - user must close manually
Closes when selection completes (click, drag-adjust). Note: Multiple mode never auto-closes
Only the Apply button closes the calendar
// 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>

3. Custom Preset Buttons (JavaScript)

JS: el.actionButtons = [{ action: 'custom', text, onClick }]

Add custom buttons with preset date ranges using the JavaScript API.

Buttons: Last Week, Next Week, Next Month
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' }
];

4. Multiple Selection Mode

selection_mode="multiple"

Allow selecting multiple individual dates or ranges programmatically.

Click dates to toggle selection (selection-mode="multiple")
No selections yet
// 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

5. External Button Control (Programmatic API)

JS prop: el.selectedRanges = [{ start, end }]

Control the picker from external buttons using reactive properties.

Use the buttons below to set ranges programmatically
No selection
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;

6. Conditional Button Visibility (JavaScript)

JS: isVisibleCallback: (ctx) => boolean ยท ctx.picker is the instance

Show/hide buttons based on picker state using the isVisibleCallback function.

Apply button only shows when a range is selected (calendar stays open with auto-close="apply")
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
  }
];

7. Dynamic Disabled State (isDisabledCallback)

JS: isDisabledCallback: (ctx) => boolean ยท ctx.picker is the instance

Enable/disable buttons dynamically based on picker state.

Apply disabled until both dates selected, Clear disabled when no selection
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 }
];

8. Dynamic Button Text (getTextCallback)

JS: getTextCallback: (ctx) => string ยท ctx.picker is the instance

Change button text dynamically based on picker state.

Apply button shows day count, Clear shows what will be cleared
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' : ''})`;
    } }
];

9. Dynamic CSS Classes (getClassCallback)

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.

Apply button changes color based on completion, Clear button becomes red when selection exists
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; }
`;

10. Dynamic Tooltips (getTooltipCallback)

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.

Tooltips update based on selection state and provide helpful context
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`;
    } }
];

11. Combined Features & Priority System

Demonstrates callback priority: *Callback functions override static properties when both are present.

Priority Chain:
โ€ข Visibility: isVisibleCallback โ†’ isVisible โ†’ true
โ€ข Disabled: isDisabledCallback โ†’ isDisabled โ†’ false
โ€ข Text: getTextCallback โ†’ text โ†’ action
โ€ข Class: getClassCallback โ†’ cssClass โ†’ ''
โ€ข Tooltip: getTooltipCallback โ†’ tooltip โ†’ ''
Clear button uses all callbacks simultaneously, demonstrating callback priority
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'
  }
];

12. Advanced Custom Actions (Business Use Cases)

Real-world examples of custom buttons for common business scenarios.

Quick access to fiscal quarters, business weeks, and rolling periods
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' }
];

13. Icons in Buttons (Font Awesome)

Add icons to buttons using HTML in the text property. Works with Font Awesome, Material Icons, or any icon library.

Note: Since the calendar uses Shadow DOM, you must import Font Awesome inside the shadow root using @import in customStylesCallback. The text property accepts HTML, allowing you to include <i> or <svg> elements.
Visual enhancement using Font Awesome icons
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; }
`;

14. ActionButton API Reference

Complete reference for all ActionButton interface properties.

Core Properties

PropertyTypeRequiredDescription
action'today' | 'clear' | 'apply' | 'custom'โœ“Button action type. Use 'custom' for custom onClick handlers.
textstringโœ“Button label (supports HTML for icons).
onClick(picker) => voidCustom click handler (required for action: 'custom').

Dynamic Callbacks (Override Static Properties)

PropertyTypeDescription
isVisibleCallback(picker) => booleanDynamic visibility control based on picker state.
isDisabledCallback(picker) => booleanDynamic disabled state based on picker state.
getTextCallback(picker) => stringDynamic button text based on picker state.
getClassCallback(picker) => string | string[]Dynamic CSS classes (single string or array).
getTooltipCallback(picker) => stringDynamic tooltip text based on picker state.

Priority System

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 โ†’ ''
๐Ÿ”Œ Server round-trip
0
The LiveView server saw 0 event(s) from the wrapper.
(pick a date anywhere on this page)