LG-4682: Resolve confirmation step button scroll-to-top, role#5705
LG-4682: Resolve confirmation step button scroll-to-top, role#5705
Conversation
**Why**: Since "Print" and "Copy" are not navigable, they should not be rendered as links, since (a) this has the effect of scrolling the user to the top of the page when clicking the buttons and (b) they are announced to assistive technology as links. Since they behave as buttons, they should be rendered as such.
It might've been nice to keep the template and somehow reference the superclass's "call" result, but it wasn't immediately clear how to achieve this.
**Why**: Generally, a custom element should be responsive to attribute changes (see "attributeChangedCallback"). It could be possible that someone would want to alter the clipboard text after the component has initialized.
d355cc0 to
bd80d83
Compare
| end | ||
|
|
||
| def call | ||
| content_tag(:'lg-clipboard-button', super, data: { clipboard_text: clipboard_text }) |
There was a problem hiding this comment.
One possible future awkwardness we may run into is that because we're just wrapping the base markup, things like tag_options[:class] will apply to the child element, not the root. A small difference, but personally I'd expect tag_options to apply to the root element.
|
|
||
| it 'allows a user to copy the code into the confirmation modal' do | ||
| click_on t('links.copy') | ||
| copied_text = page.evaluate_async_script('navigator.clipboard.readText().then(arguments[0])') |
There was a problem hiding this comment.
what's arguments here?
There was a problem hiding this comment.
what's
argumentshere?
From what I understand, evaluate_async_script wraps the given script in a function, called with a callback function argument (last argument?).
So it ends up being something like...
(function(/* callback */) {
navigator.clipboard.readText().then(arguments[0])
})(callback);arguments being the JavaScript keyword to reference the given function arguments.
There was a problem hiding this comment.
neat, I wish *they'd call it it something clearer like resolve lol 😂
*they = the webdriver/capybara devs
There was a problem hiding this comment.
Initially I'd hoped it would infer the promise value and treat it as something more like...
copied_text = page.evaluate_async_script('navigator.clipboard.readText()')(() => navigator.clipboard.readText())().then(callback);| <br> | ||
| <br> | ||
| <br> |
* LG-4682: Resolve confirmation step button scroll-to-top, role **Why**: Since "Print" and "Copy" are not navigable, they should not be rendered as links, since (a) this has the effect of scrolling the user to the top of the page when clicking the buttons and (b) they are announced to assistive technology as links. Since they behave as buttons, they should be rendered as such. * Reference super.call for ClipboardButtonComponent inherited render It might've been nice to keep the template and somehow reference the superclass's "call" result, but it wasn't immediately clear how to achieve this. * Avoid persisting initial clipboard text to instance **Why**: Generally, a custom element should be responsive to attribute changes (see "attributeChangedCallback"). It could be possible that someone would want to alter the clipboard text after the component has initialized. * Remove unused clipboard script from personal key page * Add spec to verify copied text
Why: Since "Print" and "Copy" are not navigable, they should not be rendered as links, since (a) this has the effect of scrolling the user to the top of the page when clicking the buttons and (b) they are announced to assistive technology as links. Since they behave as buttons, they should be rendered as such.
Implementation notes:
This refactors a fair bit of how these elements are rendered:
ClipboardButtonComponentNotes on
ClipboardButtonComponent:ClipboardButtonComponentto handle button details such as rendering the outline variant, (b) with a potential future goal of extracting design system components to a library gem, it would be expected that such an implementation would exist, and (c) it was a useful exercise in understanding how component inheritance may work.buttonelement, the general consensus I've read is that customized built-in elements are effectively dead-on-arrival, due to Apple's refusal to support them in Safari.<button>element and assign all necessary behaviors of a button tolg-clipboard-button(role="button", click, and keyboard handlers), but this would be rather cumbersome, and a wrapper is much more straightforward to implement.