I'd like to be able to change the background color and make some other cosmetic changes to the active paragraph bundle. Could you consider adding an 'active' class to the TR element when the 'Edit' button is clicked and remove it when the 'Collapse' button is clicked?

Likewise, it would be helpful to have a 'delete' class added when the 'Remove' button is clicked. Maybe in this case it has both 'active' and 'delete' classes? Don't know about this.

Screenshot of HTML

Comments

capellic created an issue. See original summary.

capellic’s picture

Issue summary: View changes
capellic’s picture

StatusFileSize
new432.61 KB

Played with this a bit this morning. Doesn't look like adding jQuery 'click' events to attach classes is going to work due to the TR classes getting updated when the edit form comes back via AJAX. So I thought that adding and #attributes parameter on the AJAX return paragraphs_edit_js() would work, but I don't see my test class in the document after the form is returned.

Screenshot of code

jonathanshaw’s picture

Apparently the recent paragraphs sprint has produced quite a lot of activity around the question of how edit, preview and collapse are implemented. @miro_dietiker has said he will write it up and create some meta issues, so you might want to watch for that and postpone fixing for now.

miro_dietiker’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Let's first check in 8.x.

I think the edit / preview / closed / delete state should be indicated per row so you can address them in CSS.

But we don't have an active concept, such as all are collapsed except one.
If multiple are open, we would need to track focus to determine what element is active.
Also, we would need to support nesting similar to menus and indicate parents as active-parent or so.
That said, does core have this concept? If not, i think it's not our job to invent it. We first should open a core issue to discuss it, also with focus on the accessibility aspects.

capellic’s picture

If multiple are open, we would need to track focus to determine what element is active. - @miro_dietiker

I'm in favor of this. Once a Paragraph field has several fields on it and the editor is scrolling up and down, it is easy to "lose where you are." Having some visual cue (e.g. green background color) would help the editor hone in where they left off.

I think the edit / preview / closed / delete state should be indicated per row so you can address them in CSS. - @miro_dietiker

Yes! This, too!

capellic’s picture

I've managed to do a bit of UX improvement provided by the draggable table classes. For example:

form .field-multiple-table tr:hover, form .field-multiple-table tr:active td {
  background: #e3e3e3;
}

form .field-multiple-table tr.drag-previous td {
  background: #d3d3d3;
}
miro_dietiker’s picture

I've managed to do a bit of UX improvement..

Please always include a screenshot of an improvement, otherwise the proposals don't allow us to efficiently discuss the effect and you risk no one finds time to apply the patch and test everything to find the change you propose...

capellic’s picture

@miro_dietiker, sorry about that. Since the changes involved interaction, I made a screencast.

https://dl.dropboxusercontent.com/u/4770698/Drupal-org/Paragraphs/node-2...

miro_dietiker’s picture

Thank you for the video. It's a nice alternative perspective on the Paragraphs experience. Will need to think a bit about it.

I don't understand yet though, what "active" means. In my understanding, only one item should be active and that would be the one with the last interaction.
What would you propose if i open / edit multiple paragraphs should be "active" in that case?

capellic’s picture

Right, so we don't need "active" any longer as it is handled already, but an "edited" would be useful? I imagine that it would be good to be able to see which bundles have been changed?

miro_dietiker’s picture

Yeah a changed indicator indeed makes sense.

miro_dietiker’s picture

The issue scope here shifted with the discussion.

Meanwhile we have a change indicator (icon) in the new widget.
This issue should be limited to offering a class indicating the Paragraph type per row. This already allows easy CSS styling per Paragraph Type as a first step.

If something else is still a requirement, let's create dedicated follow-ups.

arpad.rozsa’s picture

Status: Active » Needs review
StatusFileSize
new718 bytes

Status: Needs review » Needs work

The last submitted patch, 14: add_class_to_tr_element-2734303-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

arpad.rozsa’s picture

Status: Needs work » Needs review
StatusFileSize
new797 bytes
new792 bytes

Fixed the part which makes the test fail.

miro_dietiker’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

And now we want to check the class presence. :-)

arpad.rozsa’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB
new1.27 KB

Added the test to check if the class is present.

berdir’s picture

Status: Needs review » Needs work

We're trying to avoid adding more test cases to the old WebTestBase based classes and instead write new test coverage when possible in BrowserTestBase tests.

None of the existing tests there seem like a good match, so maybe just start a new test class there for generic UI/Widget tests, maybe just do a second ParagraphsExperimentalUiTest in tests/src/Functional and then in a follow-up, we can convert the existing to a browser test as well.

johnchque’s picture

Assigned: Unassigned » johnchque

Switching to Functional test. :)

johnchque’s picture

+++ b/paragraphs.module
@@ -344,6 +344,15 @@ function paragraphs_preprocess_field_multiple_value_form(&$variables) {
+    if (isset($variables['element'][0]['#paragraph_type'])) {

Do we need this if here? We are checking two lines below anyway.

miro_dietiker’s picture

+++ b/paragraphs.module
@@ -344,6 +344,15 @@ function paragraphs_preprocess_field_multiple_value_form(&$variables) {
+          $variables['table']['#rows'][$key]['class'][] = 'paragraph-type-' . str_replace('_', '-', $row['data'][1]['data']['#paragraph_type']);

We decided for paragraph-type--* .. After long religious BEM discussions, we stated that a specific type is considered a type modifier... and we don't consider it worth to repeat any of the parent block names to avoid overlength... ;-)

About the check: We first need to check if we are really inside a Paragraphs widget. We can not blindly loop over the table... Maybe check the key that is used for foreach?

johnchque’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.45 KB
new3.83 KB

Updating tests, class and adding back the condition I removed. It makes sense to have it if that's the reason. :)

miro_dietiker’s picture

Status: Needs review » Fixed

Great, now we can start to play with it in CSS. :-)

Status: Fixed » Closed (fixed)

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

cegri’s picture

I'm new to Paragraphs. I came across this issue when searching a way to add "closed" or "edit" classes, as @capellic had requested. However it seems the topic has drifted away. I'll drop my solution below for anyone interested.

I needed the "edit" class to highlight the section that is open. We use nested paragraphs. Even though all are set to "Autocollapse: All", the structure would be cleaner if we could change the border color of the open paragraph.

So I brute forced my way;

in ParagraphsWidget.php, to function formElement, around line 511

  $element += array(
        '#type' => 'container',
        '#element_validate' => array(array($this, 'elementValidate')),
        '#paragraph_type' => $paragraphs_entity->bundle(),
        'subform' => array(
          '#type' => 'container',
          '#parents' => $element_parents,
        ),
+       '#attributes' => [
+         'class' => [
+           'item-mode-' . $item_mode,
+          ],
+       ],
      );

Couple of questions:
1) Is there a better, more drupal-friendly way to do this? e.g., with a hook in my custom module.

2) I tried adding the class in paragraphs_preprocess_field_multiple_value_form similar to @arpad.rozsa'sa patch above, but could not get the item mode information there. Is it possible?

ps. Sorry for the mess! I'm not a professional programmer. I go around copying and tweaking other's codes.

edit: This does not add the class to the TR element, but to a div a few steps below. It misses only the tabledrag cell, good enough for our use. But it would be nice to style the complete TR line.