Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove background-color and box-shadow from actions #65218

Conversation

colorful-tones
Copy link
Member

What?

Addresses #65215. The hard-coded colors are not ideal. I've removed the background-color and box-shadow altogether, because it seemed like they were unnecessary for .is-selected and even :hover, focus-within. If there is a Figma design for this or further insight on what/why this small UI needs bg then let me know and I'm happy to adjust.

Why?

See #65215

How?

Remove CSS for bg color and box shadow for the small actions area.
Screenshot 2024-09-10 at 5 19 48 PM

Testing Instructions

  1. Open the Site Editor
  2. Navigate into 'Pages' and click to select one of the list items

Copy link

github-actions bot commented Sep 10, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: stokesman <presstoke@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@colorful-tones colorful-tones added the [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond label Sep 10, 2024
Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: [Feature] Data Views.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@colorful-tones
Copy link
Member Author

@jasmussen do you have insight on how to treat this small bit of UI in DataViews please?

@stokesman
Copy link
Contributor

insight on what/why this small UI needs bg

I remembered it’s for long titles:

rest hover
image image

So that’s probably going to make this trickier.

@jasmussen
Copy link
Contributor

Yep, it exists for the careful truncation, and I believe @jameskoster worked on these pieces. Agree we need a systemic approach to removing hard-coded colors. I believe this is one of the reasons the theme package (#56669) is so important to land.

CC: @ciampo

@jameskoster
Copy link
Contributor

Without these styles actions and titles will overlap:

Screenshot 2024-09-11 at 12 37 31

Hard-coded values are not great, but they're worth suffering to avoid the outcome above.

Maybe there's a different way to approach this that maintains truncation and keyboard navigation?

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, unfortunately, this won't work as-is.

But what if we add some padding to .edit-site-post-list__title span? Adding padding-right: 70px to it for example does the job because we've already got overflow: hidden and text-overflow: ellipsis:

Screenshot 2024-09-11 at 17 30 00

If the padding works, removing the background and shadow should work just fine as there will no longer be any overlap.

@ciampo
Copy link
Contributor

ciampo commented Sep 11, 2024

As @tyxla said, text truncation seems to be already in place, but the overall size of the containing element needs to be adjusted to reflect the screen estate that we want the text to occupy.

@stokesman
Copy link
Contributor

stokesman commented Sep 11, 2024

I wanted to suggest the cheapest solution would be a CSS variable for the background/box-shadow to use. It works for the hover state but the selected state’s tint is mostly transparent so doesn’t work to "truncate" the title. It could be made to work if that tint of the admin theme color was a luminosity tweak instead of alpha but I'm not sure that could be easily done at the moment.

So shortening the title in hover and select states seems more straightforward (and nicer too in that it keeps the ellipsis visible).

Diff to truncate moar on hover/select
diff --git a/packages/dataviews/src/dataviews-layouts/list/index.tsx b/packages/dataviews/src/dataviews-layouts/list/index.tsx
index 8a3f6a2973..bddf7de090 100644
--- a/packages/dataviews/src/dataviews-layouts/list/index.tsx
+++ b/packages/dataviews/src/dataviews-layouts/list/index.tsx
@@ -6,7 +6,7 @@ import clsx from 'clsx';
 /**
  * WordPress dependencies
  */
-import { useInstanceId, usePrevious } from '@wordpress/compose';
+import { useInstanceId, usePrevious, useRefEffect } from '@wordpress/compose';
 import {
 	__experimentalHStack as HStack,
 	__experimentalVStack as VStack,
@@ -144,12 +144,14 @@ function ListItem< Item >( {
 	const labelId = `${ idPrefix }-label`;
 	const descriptionId = `${ idPrefix }-description`;
 
+	const [ actionsWidth, setActionsWidth ] = useState( 0 );
+	const measureActionsWidth = useRefEffect< HTMLElement >( ( node ) => {
+		setActionsWidth( node.offsetWidth );
+	}, [] );
 	const [ isHovered, setIsHovered ] = useState( false );
-	const handleMouseEnter = () => {
-		setIsHovered( true );
-	};
-	const handleMouseLeave = () => {
-		setIsHovered( false );
+	const handleHover: React.MouseEventHandler = ( { type } ) => {
+		const isHover = type === 'mouseenter';
+		setIsHovered( isHover );
 	};
 
 	useEffect( () => {
@@ -186,6 +188,10 @@ function ListItem< Item >( {
 	const renderedPrimaryField = primaryField?.render ? (
 		<primaryField.render item={ item } />
 	) : null;
+	const primaryFieldInlineStyle =
+		isHovered || isSelected
+			? { paddingInlineEnd: actionsWidth }
+			: undefined;
 
 	return (
 		<Composite.Row
@@ -196,8 +202,8 @@ function ListItem< Item >( {
 				'is-selected': isSelected,
 				'is-hovered': isHovered,
 			} ) }
-			onMouseEnter={ handleMouseEnter }
-			onMouseLeave={ handleMouseLeave }
+			onMouseEnter={ handleHover }
+			onMouseLeave={ handleHover }
 		>
 			<HStack
 				className="dataviews-view-list__item-wrapper"
@@ -230,6 +236,7 @@ function ListItem< Item >( {
 								<span
 									className="dataviews-view-list__primary-field"
 									id={ labelId }
+									style={ primaryFieldInlineStyle }
 								>
 									{ renderedPrimaryField }
 								</span>
@@ -267,6 +274,7 @@ function ListItem< Item >( {
 							flexShrink: '0',
 							width: 'auto',
 						} }
+						ref={ measureActionsWidth }
 					>
 						{ primaryAction && (
 							<PrimaryActionGridCell
diff --git a/packages/dataviews/src/dataviews-layouts/list/style.scss b/packages/dataviews/src/dataviews-layouts/list/style.scss
index 47847967af..8fd6991173 100644
--- a/packages/dataviews/src/dataviews-layouts/list/style.scss
+++ b/packages/dataviews/src/dataviews-layouts/list/style.scss
@@ -23,6 +23,8 @@ ul.dataviews-view-list {
 			position: absolute;
 			top: $grid-unit-20;
 			right: 0;
+			// Pads __primary-field’s text truncation on hover (done in JS; see ./index.tsx).
+			padding-inline-start: $grid-unit-10;
 
 
 			> div {
@@ -45,7 +47,6 @@ ul.dataviews-view-list {
 		&.is-hovered,
 		&:focus-within {
 			.dataviews-view-list__item-actions {
-				padding-left: $grid-unit-10;
 				margin-right: $grid-unit-30;
 
 				.components-button {

What it looks like:

list-item-hover-truncate.mp4

Obviously this could be simpler by just truncating that amount in all states but if that was acceptable I don’t know why it wouldn’t have been done that way already.

@stokesman
Copy link
Contributor

Maybe there's a different way to approach this that maintains truncation and keyboard navigation?

I overlooked the keyboard navigation so that diff from my last comment lacks that but shouldn’t be hard to add in.

@colorful-tones
Copy link
Member Author

I updated and applied @stokesman suggestion.

I overlooked the keyboard navigation

I'm not sure what aspect of keyboard navigation is missing? It seems like the tab/focus order is fine. 🤔

@colorful-tones colorful-tones enabled auto-merge (squash) September 11, 2024 21:16
@colorful-tones colorful-tones self-assigned this Sep 11, 2024
@ciampo
Copy link
Contributor

ciampo commented Sep 11, 2024

Not a blocking piece of feedback, but the proposed solution feels a bit overengineered to me, and it also duplicates the layout logic (which is now defined both in JS and in CSS).

Also, the current JS-based solution wouldn't work as expected if, for any reason, the actions container width changes at runtime.

@stokesman
Copy link
Contributor

I'm not sure what aspect of keyboard navigation is missing?

Just that focus (without a click) currently won’t cause the padding to be applied so the title and actions can overlap. I suppose any effort on a fix may best be spared until it’s determined if a better approach is possible.

I agree with the general sentiment Marco expressed. It seems to me, the go-to solution would be to revise the layout so the title and actions widths are dependent. I think I assumed there’s some catch to that since it’s not that way already. Perhaps someone has some knowledge about that.

@jameskoster
Copy link
Contributor

Just that focus (without a click) currently won’t cause the padding to be applied so the title and actions can overlap.

Yup, this is a regression:

focus

It seems to me, the go-to solution would be to revise the layout so the title and actions widths are dependent

Possibly unrelated, but another important detail here was to avoid nesting interactive elements (in this case buttons) inside one another.

@colorful-tones
Copy link
Member Author

Ok, it seems that maybe my efforts are inadequate at this point. Shall I close out this PR and let someone else take a pass at a suitable solution?

@stokesman
Copy link
Contributor

stokesman commented Sep 12, 2024

Possibly unrelated, but another important detail here was to avoid nesting interactive elements (in this case buttons) inside one another.

Yes, that certainly requires some layout trickery to achieve the design. I did try tinkering on an alternate layout that seems to have promise. It is a bigger effort than the this PR’s current approach but it doesn’t need JS hackery.

I found #63299 to be a nice reference for this effort in general. There’s an interesting point regarding the selected background color brought up there:

This is a 'solid' version of rgba(var(--wp-admin-theme-color--rgb), 0.04), which should probably be a variable too given it's increasing use. I'd lean towards tackling this together, separately.

Originally posted by @jameskoster in #63299 (comment)

If that were available, it should unblock a fairly minimal resolution for this.


Shall I close out this PR

If you’d like to. I find this acceptable as short-term fix—assuming the keyboard focus can be corrected simply enough. Though I suppose the issue isn’t so grave that it requires fixing before the next release. I suspect more suitable fixes will likely miss the upcoming release.

@colorful-tones
Copy link
Member Author

I tried exploring some other color options, but the closest I could get was utilizing older Sass variables, e.g. $gray-100. I was not satisfied with any of the results.

Agree we need a systemic approach to removing hard-coded colors. I believe this is one of the reasons the theme package (#56669) is so important to land.

I agree with @jasmussen , and at this point, we'll need the new admin theme config to land to propagate and remove the older color systems.

@stokesman feel free to explore layout solutions, but I'll close this PR out.

auto-merge was automatically disabled September 13, 2024 18:52

Pull request was closed

@stokesman
Copy link
Contributor

feel free to explore layout solutions

For the sake of folks maybe still subscribed here, I’ve tried the refactored layout solution in #65376.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants