Skip to content

Conversation

elileto
Copy link
Contributor

@elileto elileto commented Mar 6, 2019

WHY are these changes introduced?

Resolves #742

UPDATE:
When a height is specified the consumer will need to also adjust the horizontal alignment of anything they put within the DropZone (including a FileUpload component.)

The DropZone determines its size (height and width) based on width only. This makes certain valid use cases, where the default DropZone height isn't appropriate, impossible.

Important Notes - Needs Discussion

This PR was originally merged #908 however there was an issue with putting a flex on Dropzone_Container which caused DropZone.FileUpload to centre horizontally however this didn't take into account the fact that DropZone could have other children.

What is up for discussion is that when a fixed height is given to the DropZone should it be up to the consumer to style DropZone's children or should we have two conditions, one that takes into account if FileUpload is the only child (therefore center it ) and the other being do not center FileUpload when there are multiple children.

There is also the fix Dan R. proposes here which adds a prop that center-aligns children and defaults to true.

WHAT is this pull request doing?

This pull request allows the consumer to set a fixed height on a wrapping parent element so that the DropZone takes its parent's height if one is provided.

Current Behaviour: (wrapped with a div given a height of 50px)
image

New Behaviour: (wrapped with a div given a height of 50px)
image

image

image

(Note: there are in between size variations (ie. small width, medium height etc.) The FileUpload will always render the smaller measurement of width or height.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Example of All Dropzone Possibilities
import * as React from 'react';
import {
  Page,
  DropZone,
  Stack,
  Thumbnail,
  Caption,
  Heading,
  Subheading,
} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Dropzones">
        <Heading> Small Height : Small Width </Heading>
        <div style={{width: 50, height: 50}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
        <Heading> Medium Height : Medium Width </Heading>
        <div style={{width: 150, height: 150}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
        <Heading> Large Height : Large Width </Heading>
        <div style={{width: 250, height: 250}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
        <Heading> ExtraLarge Height : ExtraLarge Width </Heading>
        <div style={{width: 500, height: 500}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
        <Heading> Default Height : Default Width </Heading>
        <Subheading>mobile and full width</Subheading>
        <DropZone
          onDrop={(files, acceptedFiles, rejectedFiles) => {
            this.setState({
              files: [...files, ...acceptedFiles],
            });
          }}
        >
          {uploadedFiles}
          {fileUpload}
        </DropZone>
        <Heading> ExtraLarge Height : Small Width </Heading>
        <div style={{width: 50, height: 500}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
        <Heading> Small Height : ExtraLarge Width </Heading>
        <div style={{width: 500, height: 50}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}

🎩 checklist

@elileto elileto self-assigned this Mar 6, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-1138 March 6, 2019 21:29 Inactive
@ghost ghost added the cla-needed Added by a bot. Contributor needs to sign the CLA Agreement. label Mar 6, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-1138 March 6, 2019 21:37 Inactive
@ghost ghost removed the cla-needed Added by a bot. Contributor needs to sign the CLA Agreement. label Mar 6, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-1138 March 6, 2019 21:51 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1138 March 6, 2019 22:15 Inactive
@elileto
Copy link
Contributor Author

elileto commented Mar 6, 2019

@dleroux @ry5n @danrosenthal I'm tagging you all to discuss the options that this PR produces and to also make sure I didn't miss anything in my notes above about the options. Happy to also keep looking into solutions for this in the meantime! Thank you.

@mirualves
Copy link
Contributor

Hi @elizabethletourneau! @StephPoce talked about this issue today. I just want to let you know that I'll take a look at that from a design perspective. Let me organize my next few days and all the catch up after vacation.

@mirualves
Copy link
Contributor

So I took a look at the related issues, and @elizabethletourneau helped me to understand a bit more of the problem (thank you, Liz! <3)

Taking in consideration the fact that Boolean props should often be false by default (unless there’s a legitimate exception) and, paraphrasing @danrosenthal on issue #1127, “its not typically desirable to have parents lay out their children” I believe is safe to accept that it should be up to the consumer to style drop zone’s children if they want to customize the height of the component.

I thought that maybe there’s an opportunity here to add some guidelines to the style guide in how to do centralize it horizontally once you customize the height of the drop zone.

Unrelated question: I was playing with the props and tried the Disabled one. Specifically, when we have the option of having a “Add file” button, should the button appear on the disabled state if the disabled prop is set to true?

@elileto elileto force-pushed the dz-height branch 2 times, most recently from 2b6f8c5 to 98c2440 Compare April 23, 2019 16:08
@elileto elileto changed the title [WIP][DropZone] Allow fixed height on DropZone [DropZone] Allow fixed height on DropZone Apr 23, 2019
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

Looking really good 😄 Left a few small comments but if we're 👌 from a design perspective this should be almost ready to ship since Dan, Solona and myself all gave 👍 on #908 and these pr's are almost identical

UNRELEASED.md Outdated

### Bug fixes

Constrain DropZone height based on inherited wrapper height (#1138)[https://github.com/Shopify/polaris-react/pull/1138]
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
Constrain DropZone height based on inherited wrapper height (#1138)[https://github.com/Shopify/polaris-react/pull/1138]
- Constrain DropZone height based on inherited wrapper height ([#1138](https://github.com/Shopify/polaris-react/pull/1138))

node: React.RefObject<HTMLDivElement>,
) => {
let wrapperSize = Size.ExtraLarge;
const getSize = size === 'height' ? 'height' : 'width';
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this inside the if statement since it's not used outside?

Copy link
Member

Choose a reason for hiding this comment

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

💯

wrapperSize = Size.Medium;
} else if (wrapper < Size.Large) {
wrapperSize = Size.Large;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Since the default is ExtraLarge we can 🔥 the else statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 🔥 🔥

@elileto elileto force-pushed the dz-height branch 2 times, most recently from bd9b760 to 8923025 Compare May 1, 2019 17:27
@elileto elileto requested a review from AndrewMusgrave May 1, 2019 17:28
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

🎩 ✅ cc/ @mirualves for design 👀

UNRELEASED.md Outdated
- Fixed selected state for date picker in windows high contrast mode ([#1342](https://github.com/Shopify/polaris-react/pull/1342))
- Added background into media query for Microsoft high contrast to fix skeleton accessibility. ([#1341](https://github.com/Shopify/polaris-react/pull/1341))
- Fixed the position calculation of the `PositionedOverlay` component after scroll. ([#1382](https://github.com/Shopify/polaris-react/pull/1382))
Constrain DropZone height based on inherited wrapper height ([#1138](https://github.com/Shopify/polaris-react/pull/1138))
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
Constrain DropZone height based on inherited wrapper height ([#1138](https://github.com/Shopify/polaris-react/pull/1138))
- Constrain DropZone height based on inherited wrapper height ([#1138](https://github.com/Shopify/polaris-react/pull/1138))

@chloerice
Copy link
Member

Hey @AndrewMusgrave, should I rebase and merge this, or are we still looking for design input first?

@mirualves
Copy link
Contributor

I think we're fine on the design, @chloerice !

@chloerice chloerice force-pushed the dz-height branch 2 times, most recently from 699dba0 to 0a01df2 Compare July 8, 2019 15:57
@dleroux
Copy link
Contributor

dleroux commented Jul 15, 2019

@chloerice I just rebased and tests are failing. Any idea what changed? I can dig into it but just wondering if you knew before spending too much time on this.

@chloerice
Copy link
Member

@chloerice I just rebased and tests are failing. Any idea what changed? I can dig into it but just wondering if you knew before spending too much time on this.

Tests started failing after my rebase as well. I haven't been successful in finding what's going on since the rebase, was digging into the higher priority issue. I'll be looking at this again Wednesday morning, but feel free to poke at it in the meantime!

@dleroux
Copy link
Contributor

dleroux commented Jul 23, 2019

I've rebased this and fixed tests.

@mirualves you're good with the Percy changes?

@dpersing note the a11y issues. What's the recommendation here?

@mirualves
Copy link
Contributor

@dleroux Let's investigate why it's affecting the spacing between the illustration, button and hint text. Ideally, it should have the same spacing as before.

@dleroux
Copy link
Contributor

dleroux commented Jul 25, 2019

I checked the spacing @mirualves and the Stack is behaving correctly. The new dimensions are what is causing it so I think it's fine.

@dleroux
Copy link
Contributor

dleroux commented Jul 25, 2019

Now that label is always required something is broken with the height.

@dleroux dleroux changed the title [DropZone] Allow fixed height on DropZone [WIP][DropZone] Allow fixed height on DropZone Jul 25, 2019
@dpersing
Copy link

note the a11y issues. What's the recommendation here?

@dleroux Are you referencing automated tests (which are passing now, it looks), or the a11y issues logged against the component?

@dleroux
Copy link
Contributor

dleroux commented Aug 2, 2019

Yes @dpersing. Sorry I figured it out. The accessibility fix (always having a label) is what breaks the visual layout right now.

@yourpalsonja yourpalsonja assigned dleroux and unassigned elileto Aug 27, 2019
@danrosenthal
Copy link

This PR has been open for about 6 months, I'm thinking we ought to close it until someone can commit to this change and see it through.

@dleroux
Copy link
Contributor

dleroux commented Sep 26, 2019

You see an issue with leaving it open? I'm ok with closing this but I just worry it might be completely forgotten.

@dpersing
Copy link

@danrosenthal @daniedleroux Closing the PR should be okay if the associated issue remains open?

@dleroux dleroux closed this Sep 26, 2019
@BPScott BPScott deleted the dz-height branch October 25, 2019 18:06
@alexandcote alexandcote restored the dz-height branch March 16, 2020 14:50
@alexandcote alexandcote mentioned this pull request Mar 16, 2020
6 tasks
@alex-page alex-page deleted the dz-height branch November 10, 2020 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DropZone height is not respected

9 participants