Skip to content

View.style is not consistent with Declarative UI .style property. #619

Closed

Description

@NathanaelA

If you look at the view-common.ts class; attempting to assign anything via JavaScript to the style property of the class, will throw a runtime error about the style being read only. However in the Declarative UI, you use the style property to assign a text style string to the component.

This is inconsistent, Anything I can do in the Declarative UI; should be equally do-able via JavaScript. Yes, I realize I can modify individual View.style.someProperty; but if I can use a String in the Declarative UI; I should be able to use a string via JavaScript.

I should be able to do view.style = "padding-left: 2; background-color: red" and get this applied. Just like if I put it in the Declarative UI XML.

I believe what needs to happen if I apply a inline style string to the style; that I need to reset the styles variable; re-apply App.css, then Page.css; then run the same code that is inside this._applyInlineStyle(inlineStyleString);. This way the style is reset back to scratch each time I apply a inline style string.

Any arguments against? If my position and assumptions on what needs to happen is correct, I can work on a commit patch later in the week...

Activity

  1. enchev commented on Aug 25, 2015

    @enchev
    Contributor

    Hey @NathanaelA,

    Very good question!

    Style property works very similar to HTML/JavaScript - in HTML/XML you can set the in-line string and in JavaScript you can manipulate directly the Style object using desired properties/methods. What we are missing in {N} is something similar to setAttribute where you can use the same syntax as in HTML/XML.

    If we have this method you will be able to set in-line style like this:

    var lbl = new Label();
    lbl.setAttribute("style", "color: red"):

    What do you think?

  2. NathanaelA commented on Aug 25, 2015

    @NathanaelA
    Author
  3. hshristov commented on Aug 26, 2015

    @hshristov
    Contributor

    In my opinion setAttribute is too generic. This would mean that user will be able to set other properties as well (not only style property). I believe that there should be only one way of doing things. This will give us smaller test surface, consistent API, less confusion.
    Style setter is read-only on purpose - when using intellisense the chance to make error are smaller. Otherwise you have to pass string and run the app to check if the string you set is correct.
    If there is a need to set Style from code as string it would be better to expose new method - setStyle(value: string).

  4. self-assigned this
    on Aug 28, 2015
  5. added this to the 1.3.0 milestone on Aug 28, 2015
  6. lock commented on Aug 31, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  7. locked and limited conversation to collaborators on Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions