-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(material/datepicker): Custom Datepicker #29710
Comments
Couldn't you get the same functionality by extending |
oh you can. I did not think of that. It worked, but now I have another little problem. I tried something like this <custom-form-field>
<custom-label>Choose a date</custom-label>
<input customInput [customDatepicker]="picker" />
<custom-datepicker-toggle
customIconSuffix
[for]="picker"
></custom-datepicker-toggle>
<custom-datepicker #picker></custom-datepicker>
</custom-form-field> Everything works except this I tried to extend the MatDatepickerInput /** @docs-private */
export const CUSTOM_DATEPICKER_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => CustomDatepickerInput),
multi: true,
};
/** @docs-private */
export const CUSTOM_DATEPICKER_VALIDATORS: any = {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => CustomDatepickerInput),
multi: true,
};
@Directive({
selector: 'input[customDatepicker]',
providers: [
CUSTOM_DATEPICKER_VALUE_ACCESSOR,
CUSTOM_DATEPICKER_VALIDATORS,
{ provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: CustomDatepickerInput },
],
host: {
class: 'custom-datepicker-input',
},
exportAs: 'customDatepickerInput',
standalone: true,
})
export class CustomDatepickerInput<D> extends MatDatepickerInput<D> {
constructor(
elementRef: ElementRef<HTMLInputElement>,
@Optional() dateAdapter: DateAdapter<D>,
@Optional() @Inject(MAT_DATE_FORMATS) dateFormats: MatDateFormats,
@Optional()
@Inject(MAT_FORM_FIELD)
_formField?: MatFormField
) {
super(elementRef, dateAdapter, dateFormats, _formField);
}
} here is the stackblitz |
It's because you defined the directive selector as |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Feature Description
The goal is to create a custom date picker component by extending the Angular Material Datepicker. This component will inherit all the core functionalities and styling of the Angular Material Datepicker while introducing additional features.
The problem here is that if I want to extend datepicker classes i cant create my own datepicker because there is no way to provide and extend MatDatepickerBase.
Use Case
For example I want to create my own datetime picker, but I don't have time to implement all of the datepicker logic on my own. I can just extend all classes and have the logic already there and just add what i need.
The text was updated successfully, but these errors were encountered: