WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#23851 closed enhancement (fixed)

Can we get some classes on the comment form output?

Reported by: nathanrice Owned by: nacin
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.0
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

The comment_form() function is quite useful, but styling it pretty much requires that you target the IDs, since the the outermost div and the form itself don't have classes.

If you're trying to stay as low on the specificity scale when writing CSS, not having classes available to target pretty much stops you cold.

I don't really care about the class names, though something descriptive and somewhat semantic would be preferable.

Anybody have thoughts?

Attachments (6)

23851.diff (998 bytes) - added by DrewAPicture 6 years ago.
23851.1.diff (1.6 KB) - added by obenland 6 years ago.
23851.2.diff (7.7 KB) - added by obenland 6 years ago.
.2 uses .comment-respond and includes Twenty Thirteen styles. Largely untested!
23851.3.diff (1.8 KB) - added by chrisvanpatten 6 years ago.
This is a patch I prepared for #24626 that lets you specify class_form, like you can specify class_id now. It needs to be modified slightly now to include a default class to be compatible with the modified 2013 stylesheet in 23851.2 and probably should support changing the h3 and submit button classes too.
23851.4.diff (7.8 KB) - added by obenland 6 years ago.
23851.5.diff (2.1 KB) - added by cleanshooter 6 years ago.
adding classes…

Download all attachments as: .zip

Change History (24)

#1 @philiparthurmoore
6 years ago

  • Cc philip@… added

#2 @mattyza
6 years ago

  • Cc hello@… added

As I see it, the IDs make sense, as the function is intended for single use per-output.

While adding classes would be beneficial, given your reasoning, I'd vote for adding them without removing/replacing the ID values.

This could also be handled using a filter to add the class or wrap the form in a DIV tag containing the class.

My 2 cents. :)

#3 @nathanrice
6 years ago

Oh, I'm definitely not suggesting we remove the IDs. They're necessary, actually. I'm just suggesting adding some classes.

@DrewAPicture
6 years ago

#4 @DrewAPicture
6 years ago

  • Component changed from Themes to Comments
  • Keywords has-patch added; needs-patch removed
  • Type changed from defect (bug) to enhancement
  • Version set to 3.0

23851.diff would add a filterable class to the outer div, which I think should be enough. Really, the IDs alone should be enough but this would provide some flexibility.

@obenland
6 years ago

#5 follow-up: @obenland
6 years ago

I really don't understand why we're so stingy when it comes to adding classes?

To me this is more about making it easier for child themes to override styles (IDs are almost as bad !important when it comes to that) rather than about making elements selectable in the first place (for that IDs are enough indeed).

I'd love to be able to get rid of more IDs in Twenty Thirteen.

#6 in reply to: ↑ 5 @nacin
6 years ago

Replying to obenland:

I really don't understand why we're so stingy when it comes to adding classes?

To me this is more about making it easier for child themes to override styles (IDs are almost as bad !important when it comes to that) rather than about making elements selectable in the first place (for that IDs are enough indeed).

I'd love to be able to get rid of more IDs in Twenty Thirteen.

Agree. But are these class names too generic? Like .respond?

#7 @nathanrice
6 years ago

It does seem like there ought to be better class names than just duplicating the ID. Unfortunately, I can't think of any at the moment. :-)

#8 follow-up: @GaryJ
6 years ago

.comment-respond would be a little less generic.

@obenland
6 years ago

.2 uses .comment-respond and includes Twenty Thirteen styles. Largely untested!

#9 in reply to: ↑ 8 @lancewillett
6 years ago

Replying to GaryJ:

.comment-respond would be a little less generic.

The class changes in the general-template file look great.

#10 @SergeyBiryukov
6 years ago

#24626 was marked as a duplicate.

@chrisvanpatten
6 years ago

This is a patch I prepared for #24626 that lets you specify class_form, like you can specify class_id now. It needs to be modified slightly now to include a default class to be compatible with the modified 2013 stylesheet in 23851.2 and probably should support changing the h3 and submit button classes too.

#11 @chrisvanpatten
6 years ago

Argh - I said "class_id", I meant id_form!

Basically, I don't see why you can't specify a class for the <form> tag, although the same goes for any other bit of the comment_form, I suppose. wp_nav_menu lets you specify classes (and you can hack it up nicely with walkers to target any element) but comment_form doesn't have those options. A bit frustrating to lose that control, especially when frameworks like Bootstrap (and others) specify classes they want you to use directly on your <form> elements. Wrapper divs work (most of the time), but they're gratuitous markup.

@obenland
6 years ago

#12 @nacin
6 years ago

In 24525:

Comment form: Add HTML classes.

  • #respond gains .comment-respond
  • #reply-title gains .comment-reply-titlw
  • form gains .comment-form

props obenland.
see #23851.

#13 @nacin
6 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 24526:

Twenty Thirteen: Update comment form selectors with new classes added in r24525.

props obenland.
fixes #23851.

#14 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 3.6

#15 @lkraav
6 years ago

I may have arrived a few days late to this party, but could id="submit" gain class="button"?

#16 @cleanshooter
6 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm with @chrisvanpatten we need to be able to adjust the classes... Adding them was a step in the right direction but for those template developers out there that want to be able to utilize css frame works (like bootstrap) not having access the the classes for these fields is a real bummer.

@cleanshooter
6 years ago

adding classes...

#17 @markoheijnen
6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

This ticket was closed on a complete milestone. Please create a new ticket.

#18 @DrewAPicture
4 years ago

In 34871:

Template: Introduce a new class_form argument in comment_form(), allowing customization of the form class attribute.

The static 'comment-form' class was originally added to comment_form() in [24525]. This new argument should provide needed flexibility in styling the comment form further.

Props flixos90.
Fixes #34170. See #23851.

Note: See TracTickets for help on using tickets.