Skip to content

Conversation

rafawendel
Copy link
Member

@rafawendel rafawendel commented Mar 23, 2021

What type of PR is this? (check all applicable)

  • Feature

Description

This PR is a split on #5409
This PR follows on #5418, #5419, #5420 and #5424

It is the fourth step to fix issues on standardization, interactivity and improve keyboard accessibility.

This aims to clean most remaining <a> and <button> and replace it with own semantic buttons. There should be no visual changes.

The following behavior for links, buttons, link-like and button-like components is aimed:

  • Links that look like links: <Link> - Renders <a>
  • Buttons that look like buttons: <Button> - Renders Antd <Button>
  • Links that look like buttons: <Link.Button> - Renders Antd <Button>, which is rendered as an <a>
  • Text Buttons "buttons that look like links": <PlainButton> - Renders styleless <button>

Major visual changes

Before

Kapture.2021-04-06.at.09.51.44.mp4

After

7224edb1c54069a5d9cae94f2c2bb755.mp4

@rafawendel rafawendel force-pushed the refactor-anchor-button branch from e8c4b54 to 282a4dd Compare March 31, 2021 03:34
@rafawendel rafawendel force-pushed the refactor-anchor-button branch from 282a4dd to c09b5fc Compare March 31, 2021 04:04
@rafawendel rafawendel changed the title Replace <a> and <button> with <PlainButton> (part 1) Replace <a> and <button> with <PlainButton> Mar 31, 2021
@rafawendel rafawendel requested review from gabrieldutra, kravets-levko and thielium and removed request for kravets-levko and thielium March 31, 2021 04:10
@rafawendel rafawendel self-assigned this Mar 31, 2021
return (
<li className={classNames({ done: completed })}>
<Link href={url} onClick={onClick} target={urlTarget}>
<Button type="link" href={url} onClick={onClick} target={urlTarget}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't it change a behavior? We should use Link component for all internal links

Copy link
Member Author

@rafawendel rafawendel Mar 31, 2021

Choose a reason for hiding this comment

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

<Link> should throw a type error if it gets a click handler. This was sort of a workaround. I'm trying to think in a more general solution to this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

<Link> has some logic that allows to modify URL. Using <Button> here will break those links in Databricks internal fork

Copy link

Choose a reason for hiding this comment

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

I do not agree that link should throw a type error if it gets a click handler.

It's valid to have a link perform one behavior when you click on it, and another if you middle click / open in a new tab (for example, if you want to open a modal, you don't want to refresh the page when you left click, but you do want a new page with the modal if you open a link to it in a new tab).

Copy link
Member Author

@rafawendel rafawendel Apr 7, 2021

Choose a reason for hiding this comment

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

The problem in this case is for pieces of code like this:
image

In practice, this component is sometimes a link and sometimes a button, which hurts its accessibility. If everything were typescript this wouldn't be a problem, as an href is required by <Link>. Ideally we would need to have a custom component that renders a <button> for cases like this one, or add keyboard handlers. Please let me have your opinion on this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

When Step component has a link - it can have either urlText + onClick or urlText + url + urlTarget. You can use this to decide what to render - link or button. Also, you could even update TS types to indicate this:

type StepCommonProps = { ... };

type StepLinkProps = {
  urlText: string;
  url: string;
  urlTarget: string;
}

type StepButtonProps = {
  urlText: string;
  onClick: ...;
}

type StepProps = StepCommonProps & (StepLinkProps | StepButtonProps);

In this case when you'll try to render <Step> component with onClick - TS will not allow you to use url and urlTarget, and if you'll add url and/or urlTarget - it will forbid onClick

Copy link
Member Author

Choose a reason for hiding this comment

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

Update: see #5435

@@ -1,102 +1,107 @@
div.table-name {
Copy link

Choose a reason for hiding this comment

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

This change feels bigger than the others. Can you summarize what the expected changes are to the schema browser?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changes expected are basically none. Just refactored the styles to make it easier to work with, as many of the positionings were done in a workaround-like manner. There were bugs as well: I've changed the way tooltips are positioned upon these components to make it a11y (and UI overall) friendly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Quick summary of the changes:

  • Improved nesting
  • Decoupled the button to open the drawer with the one that adds it to the editor
  • Updated the box sizing to flexbox to achieve the same result more consistently
  • Used flexbox to center, in place of paddings and margins
  • Reduced repetition re-structuring how classes are set
  • Added focus feedback
  • Added transition
  • TODO (not tracked): render of drawer has no transition

return (
<li className={classNames({ done: completed })}>
<Link href={url} onClick={onClick} target={urlTarget}>
<Button type="link" href={url} onClick={onClick} target={urlTarget}>
Copy link

Choose a reason for hiding this comment

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

I do not agree that link should throw a type error if it gets a click handler.

It's valid to have a link perform one behavior when you click on it, and another if you middle click / open in a new tab (for example, if you want to open a modal, you don't want to refresh the page when you left click, but you do want a new page with the modal if you open a link to it in a new tab).

@rafawendel rafawendel force-pushed the refactor-anchor-button branch from fac3015 to f94a4ba Compare April 7, 2021 13:04
@rafawendel rafawendel requested a review from thielium April 7, 2021 13:05

return (
<li className={classNames({ done: completed })}>
<Button type="link" href={url} onClick={onClick} target={urlTarget}>
Copy link

Choose a reason for hiding this comment

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

Why Link type="link"?

Copy link

@thielium thielium left a comment

Choose a reason for hiding this comment

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

Nothing blocking. If Percy's happy, so am I! Thanks for doing all this.

@rafawendel rafawendel force-pushed the refactor-anchor-button branch from f94a4ba to 6f06d9d Compare April 9, 2021 18:49
@rafawendel rafawendel force-pushed the refactor-anchor-button branch from 4431d66 to 8ae04d3 Compare April 10, 2021 19:03
@rafawendel rafawendel merged commit d8d7c78 into master Apr 10, 2021
@rafawendel rafawendel deleted the refactor-anchor-button branch April 10, 2021 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants