From 9dcb332f4abe8531ef841442e68f910ffa93735a Mon Sep 17 00:00:00 2001 From: zeotuan <48720253+zeotuan@users.noreply.github.com> Date: Wed, 21 Jul 2021 00:09:24 +1000 Subject: [PATCH] Fix Bugs in the "Copy article URL to clipboard" feature #14242 (#14243) * change readonly input to p tag * add pointer cursor and focus on copy post url option * add Enter keypress eventListener to copy post url option * add test for enter press event, refractor some test to click on copy post url option instead of just the image * make copy post url font bold * add scss class sidebar for dropdown && fix sidebar dropdown reaching under topheader in large screen resolution * resolve conflict with main * Update _actions.html.erb * changin markup to improve accessibility * make variable name appropriate, switch cypress to imitate user interaction * remove dump file, fix test to use alias --- .../stylesheets/components/dropdowns.scss | 12 +++++++ app/javascript/packs/articlePage.jsx | 20 ++++------- app/views/articles/_actions.html.erb | 32 ++++++++++-------- .../articleFlows/postSidebarActions.spec.js | 33 +++++++++---------- 4 files changed, 52 insertions(+), 45 deletions(-) diff --git a/app/assets/stylesheets/components/dropdowns.scss b/app/assets/stylesheets/components/dropdowns.scss index 6293a3f0a..fb4c6435a 100644 --- a/app/assets/stylesheets/components/dropdowns.scss +++ b/app/assets/stylesheets/components/dropdowns.scss @@ -17,4 +17,16 @@ max-width: 360px; width: max-content; } + + &.side-bar { + bottom: 100%; + font-size: var(--fs-base); + padding: var(--su-1); + right: var(--su-1); + @media (min-width: $breakpoint-m) { + right: auto; + bottom: auto; + top: 0; + } + } } diff --git a/app/javascript/packs/articlePage.jsx b/app/javascript/packs/articlePage.jsx index 05da2119a..c6566e81a 100644 --- a/app/javascript/packs/articlePage.jsx +++ b/app/javascript/packs/articlePage.jsx @@ -50,8 +50,8 @@ if (shareDropdownButton.dataset.initialized !== 'true') { .querySelectorAll('#article-show-more-dropdown [href]') .forEach((link) => { link.addEventListener('click', (event) => { - closeDropdown(event) - + closeDropdown(event); + // Temporary Ahoy Stats for usage reports ahoy.track('Post Dropdown', { option: event.target.text.trim() }); }); @@ -63,25 +63,19 @@ if (shareDropdownButton.dataset.initialized !== 'true') { // Initialize the copy to clipboard functionality function showAnnouncer() { - const { activeElement } = document; - const input = - activeElement.localName === 'clipboard-copy' - ? activeElement.querySelector('input') - : document.getElementById('article-copy-link-input'); - input.focus(); - input.setSelectionRange(0, input.value.length); - document.getElementById('article-copy-link-announcer').hidden = false; } function copyArticleLink() { - const inputValue = document.getElementById('article-copy-link-input').value; - Runtime.copyToClipboard(inputValue).then(() => { + const postUrlValue = document + .getElementById('copy-post-url-button') + .getAttribute('data-postUrl'); + Runtime.copyToClipboard(postUrlValue).then(() => { showAnnouncer(); }); } document - .querySelector('clipboard-copy') + .getElementById('copy-post-url-button') ?.addEventListener('click', copyArticleLink); // Comment Subscription diff --git a/app/views/articles/_actions.html.erb b/app/views/articles/_actions.html.erb index 11b4a76f2..7fc383129 100644 --- a/app/views/articles/_actions.html.erb +++ b/app/views/articles/_actions.html.erb @@ -32,47 +32,51 @@ -