如何禁用 Melt UI 日历中的许多特定日期?

问题描述 投票:0回答:1

我有这个熔化日历属性:

const {
  elements: { calendar, heading, grid, cell, prevButton, nextButton },
  states: { months, headingValue, weekdays },
  helpers: { isDateDisabled, isDateUnavailable }
} = createCalendar({
  defaultValue: new CalendarDate(year, month, day),
  locale: 'ph',
  fixedWeeks: true,
  isDateUnavailable: (date) => {
    return isWeekend(date, 'en')
  }
}); 

我还可以使用以下方法禁用特定日期:

isDateDisabled: (date) => {
  return date.day == 1
}

但我只能做一次。

我想禁用更多数组形式的日期,例如: 假期= [12/25,...]

calendar svelte sveltekit
1个回答
0
投票

您应该能够仅使用数组或集合函数。
集合效率更高,但可能不会太重要。

例如

const holidays = new Set(['12/25', ...]);
...
isDateDisabled: (date) => {
  return holidays.has(date.month + '/' + date.day);
}
© www.soinside.com 2019 - 2024. All rights reserved.