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

Display delete action when hovering over read-only term-input entries #249

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ncosta-ic
Copy link
Member

This PR changes the way by which the user gets hinted about the possibility to remove an entry out of a read-only list of term-input values.

Resolves: #243

@ncosta-ic ncosta-ic self-assigned this Feb 19, 2025
@cla-bot cla-bot bot added the cla/signed label Feb 19, 2025
@ncosta-ic ncosta-ic marked this pull request as draft February 19, 2025 10:41
@ncosta-ic ncosta-ic force-pushed the feature/term-input-delete-action-redesign branch from eba0e21 to 86e2e36 Compare February 19, 2025 14:29
@ncosta-ic ncosta-ic marked this pull request as ready for review February 19, 2025 14:30
@@ -273,12 +284,19 @@ fieldset:disabled .term-input-area [data-drag-initiator] {
outline-offset: ~"calc(-@{labelPad} + 3px)";
}

&:not(.vertical) {
--delete-action-height: ~"calc(2em + 1.75px)";
Copy link
Contributor

@sukhwinder33445 sukhwinder33445 Feb 21, 2025

Choose a reason for hiding this comment

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

Please add a comment, what is calculated here?

As this rule should only apply when read only, you can add it down below.
And you do't need to create a var. you can apply as follows:

&.read-only {
   ...

  &:not(.vertical) .delete-action {
     height: ~"calc(2em + 1.75px)";
  }
}

@@ -162,6 +164,8 @@
--search-term-highlighted-bg: var(--primary-button-bg);
--search-term-highlighted-color: var(--default-text-color-inverted);
--search-term-drag-border-color: var(--base-gray);
--search-term-delete-action-color: var(--base-remove-bg);
--search-term-delete-action-color-bg: var(--default-text-color-inverted);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please name the variable same as the less variable (--search-term-delete-action-bg).

@@ -66,6 +66,8 @@
@search-term-highlighted-bg: @base-primary-bg;
@search-term-highlighted-color: @default-text-color-inverted;
@search-term-drag-border-color: @base-gray;
@search-term-delete-action-bg: @state-critical;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please introduce @default-remove-bg and @default-delete-bg and initialize these to @state-critical.
Then use the @default-remove-bg instead of @state-critical here.

As we have the Remove button for now, please change @search-term-**delete**-action-bg to remove.

Please do the same for css variables.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really see the benefit here, as long as there's no multiple references to it. Same could be said about line 61 and 62 🤔

);
$label->addHtml(new HtmlElement('span', Attributes::create(['class' => 'invalid-reason'])));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add it in the above addHtml call, after .delete-action element.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would add it as a children of remove-action, which I don't want.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the addHtml accepts multiple parameters, so you can add it like this:

$label->addHtml(
    ... .delete-button,
    new HtmlElement('span', Attributes::create(['class' => 'invalid-reason']))
);

But that's optional, it's fine the way it is.

@@ -384,7 +384,8 @@ protected function termContainer(): TermContainer
{
if ($this->termContainer === null) {
$this->termContainer = (new TermContainer($this))
->setAttribute('id', $this->getName() . '-terms');
->setAttribute('id', $this->getName() . '-terms')
->setAttribute('delete-action-label', $this->translate('Remove'));
Copy link
Contributor

@sukhwinder33445 sukhwinder33445 Feb 21, 2025

Choose a reason for hiding this comment

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

This looks like an internal thing for TermContainer and it is only required when the input is read-only.

Please add it in the TermContainer::assemble() as follows:

...
if ($this->input->getReadOnly()) {
    $removeLabel = $this->translate('Remove');
    $this->setAttribute('delete-action-label', $removeLabel);
    ....
    new Icon('trash'),
    new HtmlElement(
        'span',
        Attributes::create(['class' => 'delete-action-label']),
        new Text($removeLabel)
     )
  ...
}

@ncosta-ic ncosta-ic force-pushed the feature/term-input-delete-action-redesign branch from 86e2e36 to 282600b Compare March 3, 2025 16:10
@@ -36,11 +36,17 @@
@base-primary-bg: #00C3ED;
@base-primary-dark: #0081a6;
@base-primary-light: fade(@base-primary-bg, 50%);
@base-remove-bg: @state-critical;
@base-delete-bg: @base-remove-bg;
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need @base-*-bg, @default-*-bg is sufficient, as these are only used to initialise @default- vars.
Please remove these variables.

background: var(--search-term-remove-action-bg, @search-term-remove-action-bg);
color: var(--search-term-remove-action-color, @search-term-remove-action-color);
border: none;
border-radius: 0.25em;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have .rounded-corners() mixin for radius.

@@ -33,6 +38,11 @@ public function __construct(TermInput $input)

protected function assemble()
{
if ($this->input->getReadOnly()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You already have the same if condition below, please add it there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not going to set that attribute for each loop iteration...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, somehow I overlooked the loop scope. You're right.
Optional: I would still omit the call getAttribute()->getValue() for the label.

new HtmlElement(
'span',
Attributes::create(['class' => 'remove-action-label']),
new Text($this->getAttribute('remove-action-label')->getValue())
Copy link
Contributor

Choose a reason for hiding this comment

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

This becomes superfluous once you have merged the if condition above. You can save the translated version in a variable and use it for attribute value and as $content for new Text(). This is what I have already suggested here.

Attributes::create([
'class' => 'delete-action-content'
]),
...Html::wantHtmlList([
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have overlooked this.

align-items: center;
background: var(--search-term-remove-action-bg, @search-term-remove-action-bg);
color: var(--search-term-remove-action-color, @search-term-remove-action-color);
border: none;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not required, as you have never defined a border, so you do not need to remove it.

@@ -264,6 +276,10 @@ fieldset:disabled .term-input-area [data-drag-initiator] {
}
}
}

&.read-only [data-index] > .remove-action {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not set a higher specificity here. It should be the same as the rule for non-vertical. So please remove >.

@@ -277,8 +293,11 @@ fieldset:disabled .term-input-area [data-drag-initiator] {
[data-index] {
position: relative;

&:not(:hover) > .remove-action {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move it a few lines down, after or before the definition of .remove-action for better readability.

@@ -75,6 +75,18 @@ fieldset:disabled .term-input-area [data-drag-initiator] {
}
}

.remove-action {
display: flex;
text-align: center;
Copy link
Contributor

Choose a reason for hiding this comment

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

text-align seems to be superfluous.

Comment on lines +329 to +334
visibility: visible;
position: absolute;
z-index: 1;
width: 100%;
top: 0;
left: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can move all these properties, which are always required (vertical or not), to the above definition for better readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even better, the above definition can be merged into this one, as the ‘Remove’ button is only needed if the input field is read-only.

Copy link
Member Author

@ncosta-ic ncosta-ic Mar 4, 2025

Choose a reason for hiding this comment

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

What definitions are you referring to with "above definition"? The one starting on line 78? I placed it there because it's considered to be style relevant and not layout relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase obviousness of how to remove a term in a term-input
2 participants