taiga-ui icon indicating copy to clipboard operation
taiga-ui copied to clipboard

🚀 - Provide some functionality to make controls readonly

Open sFeels opened this issue 1 year ago • 5 comments

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

sFeels avatar Mar 14 '23 16:03 sFeels

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

waterplea avatar Mar 15 '23 03:03 waterplea

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

sFeels avatar Mar 15 '23 07:03 sFeels

image

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

and users can

providers: [
  tuiTextfieldControlOptions({ readOnly: true })
],

splincode avatar Mar 15 '23 07:03 splincode

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?

AdrianKokot avatar Jul 10 '23 08:07 AdrianKokot

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.

waterplea avatar Jul 10 '23 08:07 waterplea