Descripción general del componente Selector de fecha Blazor

    La Ignite UI for Blazor es un componente con muchas funciones que se utiliza para ingresar una fecha mediante la entrada manual de texto o para elegir valores de fecha en un cuadro de diálogo de calendario que aparece. Ligero y fácil de usar, el selector de fechas permite a los usuarios navegar hasta la fecha deseada con varias opciones de visualización: mes, año y década. También admite propiedades de validación comunes, como restricciones de fecha mínima y máxima y campos obligatorios.

    El componente Selector de fecha Ignite UI for Blazor permite a los usuarios elegir una fecha única a través de un menú desplegable del calendario con vista mensual o un campo de entrada editable. El Selector de fecha Blazor también admite un modo de diálogo para la selección solo desde el calendario, un formato de fecha personalizable y con reconocimiento de la configuración regional, y una integración de validación.

    [!NOTE] The IgbDatePicker is a brand new component from Ignite UI for Blazor version . The old IgbDatePicker prior to this version has been renamed to XDatePicker and its respective documentation page can be found under "Deprecated Components"

    Blazor Date Picker Example

    A continuación, puede ver un ejemplo que demuestra cómo funciona el selector de fechas cuando los usuarios pueden elegir una fecha a través de una entrada de texto manual y hacer clic en el icono de calendario de la izquierda para navegar hasta él. Vea cómo renderizarlo.

    Getting Started with Blazor Date Picker

    To get started with the IgbDatePicker component, first we need to register its module as follows:

    // in Program.cs file
    
    builder.Services.AddIgniteUIBlazor(typeof(IgbDatePickerModule));
    

    You will also need to link an additional CSS file to apply the styling to the IgbDatePicker component. The following needs to be placed in the wwwroot/index.html file in a Blazor Web Assembly project or the Pages/_Host.cshtml file in a Blazor Server project:

    <link href="_content/IgniteUI.Blazor/themes/light/bootstrap.css" rel="stylesheet" />
    

    Para obtener una introducción completa a la Ignite UI for Blazor, lea el tema Primeros pasos.

    Using the Blazor Date Picker Component

    Display Date Picker

    To instantiate a IgbDatePicker in its default dropdown state, use the following code:

    <IgbDatePicker @ref="DatePicker"></IgbDatePicker>
    

    Options

    The IgbDatePicker can be bound to a date.

    <IgbDatePicker @ref="DatePicker" Value="@SelectedDate">
    </IgbDatePicker>
    
    @code {
    
        public DateTime SelectedDate { get; set; }
        public IgbDatePicker DatePicker { get; set; }
    
        protected override void OnInitialized()
        {
            this.SelectedDate = DateTime.Today;
        }
    }
    

    Projecting components

    Con las ranuras de prefijo y sufijo podemos agregar diferentes contenidos antes y después del contenido principal de la entrada.

    <IgbDatePicker @ref="DatePicker">
        <IgbIcon 
            Slot="suffix" 
            IconName="arrow_upward" 
            Collection="bootstrap" 
            Class="small" 
            @onclick="() => DatePicker.StepUp(DatePart.Month)">
        </IgbIcon>
    </IgbDatePicker>
    

    El fragmento anterior agregará un icono adicional al final de la entrada, justo después del icono de borrado predeterminado. Sin embargo, esto no eliminará el icono de alternancia predeterminado, ya que los prefijos y sufijos se pueden apilar uno tras otro.

    Personalización de los iconos de alternar y borrar

    The calendar and clear icon could be templated by using the calendar and clear slots:

    <IgbDatePicker>
        <IgbIcon Slot="calendar" IconName="calendar" Collection="material" Class="small"></IgbIcon>
        <IgbIcon Slot="clear" IconName="delete" Collection="material" Class="small"></IgbIcon>
    </IgbDatePicker>
    

    Botones de acción personalizados

    The picker's action buttons can be templated using the actions slot:

    <IgbDatePicker>
        <IgbButton Slot="actions" @onclick="() => DatePicker.ShowWeekNumbers = true">Show Week Numbers</IgbButton>
    </IgbDatePicker>
    

    Keyboard Navigation

    The IgbDatePicker has intuitive keyboard navigation that makes it easy to increment, decrement, or jump through different DateParts among others without having to touch the mouse.

    Llaves Descripción
    Mover un personaje al principio
    Mover un personaje hasta el final.
    HOGAR Ir al principio
    FIN Mover hasta el final
    CTRL / CMD + Ir al principio de la sección de fecha/hora: la actual o la izquierda
    CTRL / CMD + Ir al final de la sección de fecha/hora: actual en o a la derecha
    Centrarse en una parte de fecha/hora + Disminuye una parte de fecha/hora
    Centrarse en una parte de fecha/hora + Incrementa una parte de fecha/hora
    CTRL / CMD +; Establece la fecha/hora actual como valor del editor
    ESC Cierra la ventana emergente del calendario y enfoca el campo de entrada.

    Examples

    Dialog Mode

    The IgbDatePicker also supports a dialog mode:

    <IgbDatePicker Mode="PickerMode.Dialog"></IgbDatePicker>
    

    Display and input format

    InputFormat and DisplayFormat are properties which can be set to make the picker's editor follow a specified format. The InputFormat is locale based, so if none is provided, the picker will default to the one used by the browser.

    A good thing to note is that the Date Picker Component will always add a leading zero on the date and month portions if they were provided in a format that does not have it, e.g. d/M/yy becomes dd/MM/yy. This applies only during editing.

    DisplayFormat is used to format the picker's input when it is not focused. If no DisplayFormat is provided, the picker will use the InputFormat as its DisplayFormat.

    More information about these can be found in the IgbDateTimeInput format section.

    Increment and decrement

    The IgbDatePicker exposes StepUp and StepDown methods. Both of which come from the IgbDateTimeInput and can be used for incrementing and decrementing a specific DatePart of the currently set date.

    <IgbDatePicker @ref="DatePicker">
        <IgbIcon 
            Slot="prefix"
            IconName="arrow_upward"
            Collection="material"               
            @onclick="() => DatePicker.StepUp(DatePart.Month)">
        </IgbIcon>
        <IgbIcon 
            Slot="suffix"
            IconName="arrow_downward"
            Collection="material"
            @onclick="() => DatePicker.StepDown(DatePart.Month)">
        </IgbIcon>
    </IgbDatePicker>
    

    In Forms

    The IgbDatePicker could be used in a form element, the component's Min and Max properties act as form validators.

    In forms, we can handle the Change event of the component and update the value of the label.

    Calendar Specific settings

    The IgbDatePicker can modify some of the calendar's settings via the properties that the Date Picker exposes. Some of these include VisibleMonths which allows more than one calendar to be displayed when the picker expands, WeekStart which determines the starting day of the week, ShowWeekNumbers which shows the number for each week in the year and more.

    Internationalization

    The localization of the IgbDatePicker can be controlled through its Locale input.

    Here is how a IgbDatePicker with Japanese locale definition would look like:

    <IgbDatePicker Locale="ja-JP"></IgbDatePicker>
    

    Styling

    The IgbDatePicker component derives from the IgbInput and IgbCalendar component, so it exposes all available CSS parts. See Input Styling and Calendar Styling for reference.

    igc-date-picker::part(header) {
      background-color: var(--ig-primary-500);
      color: var(--ig-primary-500-contrast);
    }
    igc-date-picker::part(calendar-content) {
      background-color: var(--ig-surface-300);
    }
    igc-date-picker::part(date-inner current) {
      color: var(--ig-info-300);
      background-color: var(--ig-surface-300);
    }
    igc-date-picker::part(navigation-button):hover,
    igc-date-picker::part(months-navigation):hover,
    igc-date-picker::part(years-navigation):hover {
      color: var(--ig-secondary-500);
    }
    igc-date-picker::part(month-inner current),
    igc-date-picker::part(year-inner current),
    igc-date-picker::part(navigation-button),
    igc-date-picker::part(months-navigation),
    igc-date-picker::part(years-navigation) {
      color: var(--ig-info-300);
    }
    igc-date-picker::part(date-inner selected),
    igc-date-picker::part(month-inner selected),
    igc-date-picker::part(year-inner selected) {
      color: var(--ig-secondary-500-contrast);
      background-color: var(--ig-secondary-500);
    }
    

    API References

    Additional Resources