Follow-up to:
#1238484: Ability to mark the form buttons to be of a specific type (so that they can be styled differently)
#1167350: Action links were ignored
#1719640: Use 'button' element instead of empty links

Problem

  • There are various button CSS styles throughout core, which duplicate each other and are not semantic classes in the first place.

Goal

  • Remove duplicate CSS.
  • Simplify CSS.
  • Semantic classes.
  • Follow common web design standards.

Affected elements

  • Form #type 'submit' (theme_button())
  • Form #type 'button' (theme_button())
  • Form #type 'image_button' (theme_image_button())
  • Menu action links (theme_menu_local_actions()).
  • Links styled as buttons.

Affected selectors/classes

  • input.form-button (#type submit/button)
  • input.form-button-primary (^^)
  • input.form-button-danger (^^)
  • input.form-button-disabled (^^)
  • input.image-button (#type image_button)
  • a.button.add (action links)
  • a.button (links as buttons)
  • button (plain button)

Proposed solution

  1. Change .form-button into just .button.
  2. Remove element names from CSS selectors.
  3. End up with:
    .button {
      ...
    }
    
  4. Wherever anyone needs or wants a properly styled button, just use and apply .button.
  5. Replace .form-button-disabled with proper .button[disabled] selectors.

Discuss and decide

  1. .btn vs. .button — Tons of CSS in the wild uses the abbreviated class name .btn.

    Bootstrap is just a single of plethora of examples. Even though we generally do not abbreviate strings in Drupal, perhaps it would make sense to follow that very common class name, so as to make it easier to use a theme framework?

    I'm aware that Foundation uses .button, but I've seen plenty of random themes, jQuery plugins, and front-end libraries that use .btn.

  2. Image buttons are only mentioned in the above for completeness. We probably do not want to touch those and keep them explicitly separate, since an image button shouldn't get styled like any other button, as it presents a custom visual element already.

    @ry5n thankfully adjusted those to .image-button already.

Notes

  • Part of this essentially means to move Button Style module into Drupal core.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

LewisNyman’s picture

I support this.

I'd rather have .button just because it's less ambiguous and the class wouldn't be common enough to raise a page weight concern.

sun’s picture

FWIW, my pedantic self also vastly prefers .button.

I only raised this, because I've seen so many instances of .btn in the meantime that I thought it would be worth to discuss.

sun’s picture

I also just looked up what jQuery UI is doing for buttons, but it essentially does nothing, or rather, only applies a flood of custom, jUI-specific CSS classes via JavaScript:

ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only

I'm fairly sure we don't want to go there. ;-)

sun’s picture

Issue summary: View changes

Updated issue summary.

ry5n’s picture

My take on this is that we want to create a unified set of styles for any UI control that appears as a button (including, in a perfect world, the Ctools dropbutton). I think button markup cleanup should be part of this too, if need be. Does that make sense?

Specifics:
- I vastly prefer .button to .btn
- No jQuery UI, please :)
- +1 for a SMACSS/OOCSS approach, plus Bootstrap and Foundation as real-world inspiration.

Speaking of which, Bootstrap supports a darn good set of interaction patterns in their button and its compound variations. We can consider using it as a guide, although we likely won't be implementing the compound ones now.

sun’s picture

Yep, let's not get into scope-creep here though ;)

This issue should focus on .button and .button only. That said, looks like we have a winner. ;)

That essentially means we have a decision and can move forward with an actual patch. We're sorta blocked on #1238484: Ability to mark the form buttons to be of a specific type (so that they can be styled differently) though, since that one changes a dozen of form button styles across the board, so we should wait until that has been committed. :)

LewisNyman’s picture

I've opened a new issue on consolidating the design of the buttons in Seven. #1848292: Consolidate Seven button styles

sun’s picture

Status: Active » Needs review
FileSize
8.68 KB

Not sure whether I covered everything from the summary, but attached is my initial prototype that I want to propose.

Looks + works fine in Seven. (fun, fun, we do not actually expect differences here ;))

sun’s picture

FileSize
2.85 KB
11.15 KB

Hah, I forgot about the fun part — merging the new a.button.add styles of action links :)

That said, what do we do about that .add class? It appears a bit out of line with the new .button-primary and .button-danger classes, no?

Do we want to rename that into .button-add?

Done so in attached patch.

ry5n’s picture

On my phone, can't review code yet, but some ideas re #8.

.button-add would make some sense, but what about this:

The main difference between .button-add and .button-primary is the presence of the '+' icon. What about moving all core icons into a reusable Icon UI component? This would be a container for sprite-based or icon-font-based icons, using markup like <i class="icon icon-add">add</i>. (The text in the icon would be hidden but available to screen readers in the usual way.) The icon component could be used anywhere, including inside action links. Then, if we still need to treat action links themselves differently from all other buttons (like for example making them slightly smaller), this can be done with a .button-small child class.

sun’s picture

+1,000 to #9 — I actually discussed that with many others in the past already, but never got around to create a dedicated issue for it. :)

However, let's do that in a separate follow-up issue. Since that issue will be bound to feature freeze, we have some pressure to get both this and that follow-up issue ready in time... ;)

sun’s picture

Oh, and besides that, I additionally think that the action link buttons actually present a special kind of button with special visual importance and implications.

The only argumentation I'd be able to follow would be that the wrapping .action-links container provides sufficient context to style them differently... but then again, I'd think I'd like to see "add" buttons to appear in a consistent way throughout a site, regardless of whether they appear in the 'dedicated' action link buttons area/container or not. (?)

ry5n’s picture

I'd rather not have styles dependent on a container in this case, as we can clearly imagine action buttons appearing on their own.

Some of the architecture for this might actually depend on the style choices of the admin theme. What we *could* do is actually use a completely different base class for actions, eg. 'action', then Seven could have .action 'extend' .button like so:

before

.button {
  /* button styles */
}

after

.button,
.action {
  /* button styles */
}

.action {
  /* any base .button overrides and additional styles */
}
sun’s picture

Isn't that the same as .button-add, just colored .action though? ;)

ry5n’s picture

Technically it could be, although to me, .button-add would be a sub-class of .button, meaning you would have to apply .button and .button-add. Put another way, .button-add build on top of the .button styles. Whereas a name like .action makes it clear this is a separate base class, not necessarily styled as a button. In Seven, we would make .action 'inherit' from .button as in the example above, so all you need to apply is .action. I hope that makes sense.

BTW I'm no proposing this, but it would be how to solve de-coupling action links from the button style while still having consistency in Seven.

LewisNyman’s picture

I was just about to suggest the same as #9 as part of the solution for #1848292: Consolidate Seven button styles. Let's abstract out icons completely from button styling. We have icons all over the toolbar now, let's create an icon class so it's usable across elements.

I don't know if action links represent a different semantic to the user than a regular button and if they do what the difference is, that's a key point we need to agree on.

sun’s picture

I'm open to whichever solution we can agree with :)

Two thoughts just crossed my mind:

1) Aren't all buttons actions? (from an interaction perspective) — We'd probably need a better name than .action, I think.

2) We're probably struggling hard, because the usability/visual/interface pattern for action links is not really clearly defined. In Seven, the links were presented as "Add something" operation and that's why we improved their styling and added the .button.add class recently — but reality is, not all action links that appear there are actually "Add something" links; a couple of pages in core are showing links that are rather of the form "Manage something" there. — In turn, .button-add essentially makes a big assumption which is not necessarily true, but the problem is not that it is making that assumption, but instead, the problem is that the pattern is not clearly defined and not consistently implemented.

3) .button-add would indeed presume that add-action-links ought to be styled as buttons. I can see the problem there. But at the same time, I also think that the application needs to set some basic interface pattern standards, in the same way we have tabs/local tasks and vertical tabs. In turn, I'm not sure whether making the assumption that action links should appear as buttons is good or bad (as in, too much).

Oyoyoy... my fear this is getting very meta ;)

Technically, this issue shouldn't really have to dive this deep into interface/pattern questions, since the main objective is a bare and simple refactoring of CSS classes. I wonder whether we can agree on a lowest common denominator and rather try to quickly move forward? :)

Would it make sense to create a follow-up issue for the .button-add vs. .action class name, so we can discuss that in isolation without blocking this issue? :)

ry5n’s picture

I'm not sure we even need the follow-up. In Seven, they now look like buttons, so let's stick with .button-{something}. Perhaps .button-local-action to make it more general than .button-add. (As a side effect of that, the .action-links wrapper could be renamed .local-actions.)

sun’s picture

OK, not sure I want to change the .action-links class as part of this issue, but otherwise, I think that makes sense.

Let me try to summarize:

1) We have .button + button for general button styling.

2) .button.add is changed into .button-action.

3) In a separate follow-up step, we move the visual "add icon" presentation into a new .icon-add class, which gets applied to action links.

Makes sense?

sun’s picture

FileSize
3.59 KB
11.12 KB

Attached patch implements that.

I do not see a visual change compared to HEAD in any core theme, so I'm not creating/attaching screenshots.

ry5n’s picture

@sun yes on the summary, except that last point. For icons, I'm suggesting .icon-add be applied to its own markup element: <i class="icon">icon text for screen readers</i>. The advantage to doing it this way is that icons can be given a width and height exactly matching the desired pixel area in a sprite, such that you never have situations where adjacent icons in the sprite start bleeding into the element when you make it bigger.

sun’s picture

@ry5n: Cool with me, though that's actually a detail left for the icon follow-up issue for #9. ;) Also, please note that we have to create + discuss + implement + test the icon feature in no more than 7 days... so we better hurry up and get this partial blocker done ASAP. ;) I'll try to create the icon issue tonight.

Does that mean that we're actually RTBC here? :)

Status: Needs review » Needs work

The last submitted patch, button.19.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
2.07 KB
9.05 KB

Reverted EntityFormController changes.

Those were irrelevant here and caused the test failures. We badly need to clean that up, but let's do that in a separate issue.

Status: Needs review » Needs work
Issue tags: -Needs themer review, -API clean-up, -TX (Themer Experience)

The last submitted patch, button.23.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
Issue tags: +Needs themer review, +API clean-up, +TX (Themer Experience)

#23: button.23.patch queued for re-testing.

ry5n’s picture

#23 is looking good (thanks for adding that extra button test).

The only bug I found was the with the dropbutton; the base button's hover and active styles were interfering.

One other issue: the disabled attribute isn't valid on anchors (it's not a global attribute either). It's probably also a functional issue, since [disabled] links will appear disabled, but will still work in most browsers.

The attached patch fixes the dropbutton and qualifies .button[disabled] to input.button[disabled].

xjm’s picture

sun’s picture

An interdiff would have been nice :)

(btw, I'm developing almost all of these patches in the Platform sandbox repository, and just granted you write access, so if you're versed enough with git and want to put your branches in there, go ahead :) The project page contains some instructions for branch names, and the git diffup alias performs all the other magic)


Yeah, I looked up the spec for the disabled attribute, too — but regardless of whether it applies to form controls only, is there a reason to qualify it with input? I didn't see one, so I left it unqualified. That said, I don't really care, too ;)

That said, the (pre-existing) .button styles in system.theme.css actually have unintended consequences:

theme-button.28.png

Thus, I think we need to change those to .button-action, since that was their actual/original target/purpose.

What's also apparent by the screenshot is that we do not have any sensible default margin between buttons right now. This problem actually seems to be resolved independently by each theme (and thus, the solution is identical to all themes and should be resolved by system.theme.css instead).

Additionally done that, since it means a vast simplification across the board.

I also just had the neat :first-child margin-nuking idea for the button styles - which works for both LTR and RTL at the same time! :)

The approach works excellently for .button, because they are normally stacked up directly within a .form-actions container. It does not work for action link buttons, since each button is the only element within a list item of the action links item list. We continue to use the LTR/RTL margin-futzing for those list items.

That said, verifying and testing RTL revealed that the styles for action links are terribly broken currently ;) But luckily, the solution is to simply remove styles from Seven style-rtl.css — which is further, ultimate proof that we're on to some awesome design/theme experience in D8! :-)

(btw, I can't wait for design_test.module to get committed as part of the details patch, so we can simplify all of this horrible manual testing...)

ry5n’s picture

Sorry about the lack of interdiff, it's my lack of experience with git showing. I guess the reason to qualify the input.button[disabled] is so that those styles wouldn't affect links with the disabled attribute, but I'm not sure it makes much of a difference really.

sun’s picture

No worries :)

To me this looks pretty much complete — let's make sure to quickly move forward here.

sun’s picture

Issue tags: +Web Design Standards

Adding a new issue tag :)

Meanwhile, also created: #1849712: Add theming template and prepare logic for rendering icons

ry5n’s picture

Issue tags: -Web Design Standards
FileSize
51.93 KB

@sun Agreed. Reviewing this, I noticed a problem in Bartik with the new toolbar:

screen of toolbar in Bartik, patch 28

I wonder if we should actually style *only* elements with .button, meaning you'd even need .button on <button>. This may sound a bit crazy at first, but I think might be the best approach. It makes the styles truly markup-agnostic and prevents conflicts with <button> elements that are styled differently for use cases like the toolbar. What do you think?

sun’s picture

Issue tags: +Web Design Standards
FileSize
2.62 KB
10.57 KB

That sounded very scary at first sight...

...but actually, I guess it's not only resolving that Toolbar case, but also the sorta upcoming case of #1719640: Use 'button' element instead of empty links — which intends to use button.link to essentially to do the opposite; i.e., styling buttons as links.

It also means we can revert the adjustments for .dropbutton button styles. (yay?)

In light of that, that makes perfect sense to me. It also seems to be in line with framework themes, which equally require you to apply the .button class to all elements.

Attached patch does so.

ry5n’s picture

@sun I was thinking specifically of that issue as well :)

Reviewed the latest, looks really great. One thing is Seven has full-width buttons on small screens, which needed only a single line change to play well with the new system.css margins. I think this is RTBC :D

sun’s picture

Status: Needs review » Reviewed & tested by the community

Yay, thanks! I agree, this looks ready to me.

sun’s picture

Issue summary: View changes

Updated issue summary.

sun’s picture

Updated issue summary accordingly.

sun’s picture

Title: Refactor generic form/link button CSS styles » Refactor and introduce generic button CSS styles for forms and links
Category: task » feature
webchick’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs screenshots

Can we get some before/after screenshots here?

sun’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
5.76 KB
6.89 KB

This is plain markup/CSS class refactoring - screenshots do not show a difference, except for the now default/standardized horizontal margin between buttons in form actions.

Before:

css-button-before.png

After:

css-button-after.png

sun’s picture

sun’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs screenshots, +Needs themer review, +API clean-up, +TX (Themer Experience), +Web Design Standards

The last submitted patch, core--refactor-button-css-1845728--34.patch, failed testing.

sun’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
10.78 KB

Re-rolled against HEAD.

Fabianx’s picture

+1 for RTBC

sun’s picture

#43: theme.button.43.patch queued for re-testing.

catch’s picture

Title: Refactor and introduce generic button CSS styles for forms and links » Change notice: Refactor and introduce generic button CSS styles for forms and links
Category: feature » task
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Looks great. Don't see how this is a feature, it's just refactoring some CSS.

ry5n’s picture

Change notice posted: http://drupal.org/node/1878536

catch’s picture

Priority: Critical » Normal
Status: Active » Fixed

Thanks!

plach’s picture

Title: Change notice: Refactor and introduce generic button CSS styles for forms and links » Refactor and introduce generic button CSS styles for forms and links

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.