Problem/Motivation
I'm trying to setup the preview view modes, so my authors can close the items. The trouble is that the twig templates will add the relevant libraries for each component, which brings in extra css from the module. In this case, the css adds:
.paragraph--type--uswds-card-group-regular .usa-card__container .usa-card__header .card-link:after,
.paragraph--type--uswds-card-group-flag .usa-card__container .usa-card__header .card-link:after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: "";
}This after has the byproduct of overlaying that link over the upper 3/4 of the page:

Steps to reproduce
Configure your your paragraph fields closed mode to preview, optionally configure preview view modes for your components. For example card/card groups. Then edit a node with one of these components and collapse it so Drupal renders the preview.
Proposed resolution
Should these libraries even end up on the admin section? We could move the library attachment out of the twig and into preprocess with some logic.
More immediately, the following css added to your admin theme will workaround it:
.paragraph--type--uswds-card-group-regular .usa-card__container .usa-card__header .card-link:after,
.paragraph--type--uswds-card-group-flag .usa-card__container .usa-card__header .card-link:after {
content: none;
}Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | Screen Shot 2022-09-06 at 10.57.35 AM.png | 872.73 KB | smustgrave |
| Screenshot 2022-08-26 164228.png | 76.84 KB | devkinetic |
Issue fork uswds_paragraph_components-3306337
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
devkinetic commentedComment #3
smustgrave commentedI'm fine with moving the libraries into hooks vs templates.
Comment #4
devkinetic commentedWhat exactly are these styles for? Are they targeted for the admin side, or targeted for the front end? What do they provide that the uswds base theme and build system doesn't provide? I haven't played around enough with front end to break this down. Seems to me they should only be added on the front end, and only if they provide some sort of drupal / uswds integration that isn't out-of-the box from the theme.
While we sort out the correct logic, I'm starting a branch to move the library additions into a hook.
Comment #6
devkinetic commentedComment #7
smustgrave commentedThey are attended for the frontend. Trying to remember all the use cases but for alerts, for example, if you added more than one it wouldn't add any space between them.
For the cards it's actually a 508 fix I'm doing. Since we are allowing entire cards to be links it needed a special ordering for screen readers. Found out if you wrap an image, title, and body in a link tag the screen reader reads it as one string and probably doesn't make sense. So only wrapping the link around the title and using css so you can still click on the entire card. USWDS doesn't do that feature so they didn't have the css for it.
Comment #8
devkinetic commentedLogic options:
Comment #9
smustgrave commentedI'm fine with disabling on the preview mode.
haha you'd be surprised. Seen other tickets where people are doing this with uswds.
We can hold on this now. If disabling on preview becomes an issue we can look into fixing but I doubt it will be a problem.
Comment #10
devkinetic commentedI've updated the merge request with the specified logic. This is ready for review.
Comment #11
devkinetic commentedComment #12
devkinetic commentedJust noticed that the accordion library is not currently being used, is this on purpose? I can add it in, or remove the css/yml if it is no longer needed.
Comment #13
smustgrave commentedIf it's not being used we can go ahead and remove. module was pulled in different directions before settling.
I plan to review this today fyi.
Comment #14
devkinetic commentedSounds good, took care of the unused lib so we should be good now.
Comment #15
smustgrave commentedSo for the scope of this ticket the MR appears to be working. But wonder if a new ticket should be opened to make the "preview" form mode better.
For example this is what I see when adding an accordion and card. Doesn't look that great.
Comment #16
smustgrave commentedWhat if we did a check for the edit url and not load the uswds templates.
Or would that go against your use case you are trying to solve?
Comment #17
devkinetic commentedThat would not break my use case. This is all on node/edit/%.
Comment #19
smustgrave commentedAdded a check in the hook_theme().
Merged!
Thanks for all the work on this!
Comment #20
smustgrave commentedUndid that change I did and just merged the original MR.
Hook_theme() is cached so wasn't working the way I thought.
Comment #22
smustgrave commentedFYI I had to revert a change in the hook_theme but that should not break the fix done here. But just wanted to note.Scratch that the 2.3 branch was just off a bit.