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

[Grid] Support for alignSelf prop #9098

Closed
1 task done
damianobarbati opened this issue Nov 11, 2017 · 12 comments
Closed
1 task done

[Grid] Support for alignSelf prop #9098

damianobarbati opened this issue Nov 11, 2017 · 12 comments
Labels
component: Grid The React component. new feature New feature or request
Milestone

Comments

@damianobarbati
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

As the title says, adding align-self rule to Grid component like <Grid item={true} alignSelf={'flex-end'} /> would be great => https://css-tricks.com/almanac/properties/a/align-self/

@oliviertassinari oliviertassinari added waiting for 👍 Waiting for upvotes new feature New feature or request labels Nov 11, 2017
@oliviertassinari
Copy link
Member

The Grid component tries to stick to the nominal use cases (both for API size and bundle size constraints). If you need more advanced use cases, you might want to extend the component in userland.

@oliviertassinari
Copy link
Member

I have added the waiting for users upvotes tag. I'm closing the issue as I'm not sure people are looking for such abstraction. So please upvote this issue if you are. We will prioritize our effort based on the number of upvotes.

@oliviertassinari oliviertassinari removed the waiting for 👍 Waiting for upvotes label Nov 30, 2019
@mcobzarenco
Copy link

Stumbled across this issue, I am struggling to figure out how to achieve the equivalent of flexbox's align-self: xxx using <Grid>

    <Grid
      container
      direction="column"
      alignItems="stretch"
      spacing={3}>
   
      <Grid item alignSelf="center"> //???
          <div> Centered text  </div>
      </Grid>

   </Grid>

@IAmMarcellus
Copy link

@mcobzarenco I don't think they ever fixed this issue. Somone created another issue for it here: #11552, but it was closed as a part of #6140, although that never resolved it. @oliviertassinari any word on if this will be resolved?

@oliviertassinari oliviertassinari added the component: Grid The React component. label Feb 26, 2020
@oliviertassinari oliviertassinari changed the title [Grid] support for alignSelf prop (feature request) [Grid] Support for alignSelf prop Feb 26, 2020
@oliviertassinari oliviertassinari added this to the v5 milestone Feb 26, 2020
@oliviertassinari
Copy link
Member

This feature should come for free with #15561

@vicasas
Copy link
Member

vicasas commented Dec 29, 2020

@damianobarbati @mcobzarenco As an alternative solution, the Box component can be used to pass it through the Grid prop component, thus injecting us with the functionalities of the Box api that includes alignSelf

Example

<Grid component={Box} item alignSelf='center'>
   ...
</Grid>

This works for me

@oliviertassinari
Copy link
Member

@vicasas We have been discussing making this the default in v5 with @mnajdova.

@vicasas
Copy link
Member

vicasas commented Dec 29, 2020

@oliviertassinari @mnajdova Can the following be used?

export const styles = () => ({
  'align-self-xs-start': {
    alignSelf: 'start',
  },
  'align-self-xs-center': {
    alignSelf: 'center',
  },
  'align-self-xs-end': {
    alignSelf: 'end',
  },
})

const Grid = React.forwardRef(function Grid(props, ref) {
  const {
    alignSelf = 'stretch',
  } = props

  const className = clsx(
    classes.root,
    {
      ...
      [classes[`align-self-xs-${String(alignSelf)}`]]: alignSelf !== 'stretch',
      ...
    },
    classNameProp,
  );

  return <Component className={className} ref={ref} {...other} />;
}

@oliviertassinari
Copy link
Member

@vicasas
Copy link
Member

vicasas commented Dec 30, 2020

@oliviertassinari I tried to make a POC but I don't understand how to use the API from the import. I've never done it like this. Is it necessary to use style-component to wrap flexbox? I don't know if there will be any thread of this maybe to look at there.

@oliviertassinari
Copy link
Member

@vicasas The first step is to migrate the component from @material-ui/styles to @material-ui/styled-engine. The closest example is in #24114. Second step is to apply the flexbox style functions. Et voilà.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 27, 2021

@mnajdova has solved the issue in v5.0.0-alpha.24 with #24499:

import * as React from "react";
import Paper from "@material-ui/core/Paper";
import Grid from "@material-ui/core/Grid";

export default function CenteredGrid() {
  return (
    <Grid container flexDirection="column">
      <Grid item alignSelf="flex-end">
        <Paper
          sx={{
            p: 2,
            color: "primary.contrastText",
            bgcolor: "primary.main",
          }}
        >
          xs=6
        </Paper>
      </Grid>
    </Grid>
  );
}

Capture d’écran 2021-01-27 à 14 10 14

https://codesandbox.io/s/centeredgrid-material-demo-forked-rty3m?file=/demo.tsx:0-508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. new feature New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants