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

XWIKI-22495: Missing text content in the resource picker dropdown #3612

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Sereza7
Copy link
Contributor

@Sereza7 Sereza7 commented Oct 30, 2024

Jira URL

https://jira.xwiki.org/browse/XWIKI-22495

Changes

Description

  • Added a translated title/content to the dropdown toggle
  • Updated the style to allow for the use of .sr-only in this specific context (overriding CKEditor CSS reset)

Clarifications

  • The CKEditor CSS reset works on .cke_reset_all *. Pretty much anything more specific than .sr-only is enough to take priority over it. I decided to go with a local definition (only useful for this specific element). If any other sr-only elements are needed in our CKEditor UI, we might want to write a style rule for all of them with .cke_reset_all .sr-only.

Screenshots & Video

No visual changes in between before and after the PR, except for the title tooltip appearing when hovering the button.
Here is what the UI would look like after the changes proposed in this PR:
Screenshot from 2024-10-30 16-43-29

Executed Tests

Manual tests on a local instance, see screenshot above.
As far as I can see, integration-tests should not be impacted by this change.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • 15.10.x
    • 16.4.x

* Added a translated title/content to the dropdown toggle
* Updated the style to allow for the use of .sr-only in this specific context (overriding CKEditor CSS reset)
@@ -35,7 +36,9 @@ define('resourcePicker', [
'<button type="button" class="resourceType btn btn-default">' +
'<span class="icon">' +
'</button>' +
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">' +
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" ' +
'title="' + translations.get('dropdown.toggle.title') + '">' +
Copy link
Contributor

Choose a reason for hiding this comment

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

is the result of translation.get html safe or does it needs an xml escaping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/search?q=repo%3Axwiki%2Fxwiki-platform%20translations.get(&type=code

There's no other use where we just use it as plain HTML. I'm pretty sure using it in Element.text escapes it.
From what I can see at

var getTranslation = function(key) {
var translation = this[key];
if (typeof translation === 'string') {
// Naive implementation for message parameter substitution that suits our current needs.
for (var i = 1; i < arguments.length; i++) {
translation = translation.replace(new RegExp('\\{' + (i - 1) + '\\}', 'g'), arguments[i]);
}
} else {
translation = key;
}
return translation;
};

the translation function doesn't care about escaping (which is correct as far as I know).
I couldn't find a proper way to escape things directly in here (except implementing a barebones HTML escaper ^^').
I decided to fill up the template with the translations using jquery methods. These methods escape their inputs so it's safe.

See edc6d87

Here is what a quick test of the updated PR gave me (I didn't properly move the translations to my instance - which is why it's somewhat broken in the screenshot.):
image

@@ -19,6 +19,18 @@
*/
#template('colorThemeInit.vm')

/* We need to redefine this class to have better priority than the CKEditor CSS reset. */
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be interested to have an explanation of why this class is needed.
What happens when this CSS is not defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

If this CSS is not defined, we cannot use the XWiki defined class .sr-only to hide visually elements that are only useful for screen readers.
This is an issue because it's a class we should be able to rely on in all our codebase.

The CKEditor reset takes precedence over our definition of .sr-only and decides the style of this element:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment to provide more detail in 5c7dfef 👍

@manuelleduc manuelleduc added the backport stable-15.10.x Used for automatic backport to 15.10.x branch. label Dec 31, 2024
Comment on lines 22 to 23
/* We need to redefine this class to have better priority than the CKEditor CSS reset.
Without this higher priority redefinition, the elements with this class are still shown. */
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not exactly clear to what is redefined, and why exactly this redefinition is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the comment in 3fe586f to be more explicit. Let me know if there's still something unclear.

For maintainability, I avoided providing links in the comment.

Copy link
Contributor

@manuelleduc manuelleduc left a comment

Choose a reason for hiding this comment

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

lgtm, maybe a quick check from @mflorea as well?

@manuelleduc manuelleduc requested a review from mflorea December 31, 2024 15:31
@Sereza7 Sereza7 added backport stable-16.10.x and removed backport stable-15.10.x Used for automatic backport to 15.10.x branch. labels Jan 3, 2025
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

If any other sr-only elements are needed in our CKEditor UI, we might want to write a style rule for all of them with .cke_reset_all .sr-only.

I think I prefer the generic rule because there's a high chance we'll need this on other parts of CKEditor UI. Maybe put this in CKEditor.EditSheet .

Comment on lines +39 to +40
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">' +
'<span class="sr-only"></span>' +
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to keep the indentation.

Comment on lines +53 to +54
resourcePicker.find('button.dropdown-toggle').first().attr('title', translations.get('dropdown.toggle.title'));
resourcePicker.find('button.dropdown-toggle .sr-only').first().text(translations.get('dropdown.toggle.title'));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
resourcePicker.find('button.dropdown-toggle').first().attr('title', translations.get('dropdown.toggle.title'));
resourcePicker.find('button.dropdown-toggle .sr-only').first().text(translations.get('dropdown.toggle.title'));
resourcePicker.find('button.dropdown-toggle').attr('title', translations.get('dropdown.toggle.title'));
resourcePicker.find('button.dropdown-toggle .sr-only').text(translations.get('dropdown.toggle.title'));

No need to limit the collection to the first item.

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.

3 participants