taiga-family / taiga-ui

Angular UI Kit and components library for awesome people
https://taiga-ui.dev
Apache License 2.0
3.21k stars 439 forks source link

🚀 - Provide some functionality to make controls readonly #3868

Open sFeels opened 1 year ago

sFeels commented 1 year ago

Which @taiga-ui/* package(s) are relevant/releated to the feature request?

No response

Description

Please add some feature which will allow to make every control state readonly

waterplea commented 1 year ago

@sFeels all controls have readOnly input. Could you clarify your issue?

sFeels commented 1 year ago

I mean something that can make every control readonly at once from the outside component template

splincode commented 1 year ago

image

we need readOnly = false; change to readOnly = this.option.readOnly;

and users can

providers: [
  tuiTextfieldControlOptions({ readOnly: true })
],
AdrianKokot commented 1 year ago

I'd like to implement this, but I need to clarify something. @splincode mentioned tuiTextfieldControlOptions. The flow of the readOnly input is: TuiAbstractControl -> SomeComponent -> TuiPrimitiveTextfield, so using the additional TextfieldControlOptions property won't work because the value of the provided option will be overridden by either TuiAbstractControl or SomeComponent.

To make it work with TuiTextfieldControlOptions, it would have to be used in the constructor of the component like this

class TuiInputCardGroupedComponent {
    constructor(
        @Inject(TUI_TEXTFIELD_WATCHED_CONTROLLER)
        readonly controller: TuiTextfieldController
    ) {
        this.readOnly = this.controller.options.readOnly;
    }
}

or create separate TuiControlOptions and pass the controller.options to AbstractTuiControl in the constructor parameter.

However, if extending the AbstractTuiControl constructor is an option, I think it's better to just add DI for AbstractTuiControl. That way we'll provide the readOnly provider for all controls, not just the ones with TuiTextfieldController.

@waterplea, @splincode What do you think? Do you prefer any solution?

waterplea commented 1 year ago

I think it's better to wait on this one before we update to Angular 14+ so we can use the inject function. Otherwise it would make all constructors messy.