Frage

Google closure offers a custom checkbox component which seems to create an overhead to render a simple checkbox. Why is it worth using it?

I'm using the Google closure framework heavily and I was wondering if using those input replacement components makes sense.

The answer can be extended to explain also if a text input should be replaced also with a goog.ui.Textarea.

War es hilfreich?

Lösung 2

I came to the answer myself: both are good depending on their use. All these custom inputs of google closure have something in common: they extend goog.ui.Control. This component is pretty useful for handling states: disabled, hover, active and focused. This means the following thing:

  1. If you're just creating a form for a new database record, it makes little sense to use these components. It's an overkill. A simple input which receives the data can even be sent by post (a goog.ui.Control isn't able to do this by itself).
  2. If you're creating a dynamic web interface which handles events and/or states, it's far better to use a goog.ui.Control given it already handles these events and it's capable of some default event and state-change handling with it's ascendants/descendants.

The only exception here is if you have a mix of goog.ui.Controls with form inputs and you want an unified user experience. In which case you have to play with style-sheets or sacrifice complexity/maintenance for either of them.

Andere Tipps

You don't have to. But sometimes you may want to use it, since goog.ui.CheckBox has tree states: CHECKED, UNCHECKED, UNDETERMINED, while a plain checkbox has only two states.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top