-
Notifications
You must be signed in to change notification settings - Fork 209
feat: Table cell align for all cells #3318
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import * as baseComponentHooks from '../../../lib/components/internal/hooks/use-base-component'; | ||
| import Table from '../../../lib/components/table'; | ||
|
|
||
| const useBaseComponentSpy = jest.spyOn(baseComponentHooks, 'default'); | ||
|
|
||
| test('reports cellVerticalAlign and columnDefinitionsVerticalAlign correctly', () => { | ||
| const def = (id: string, verticalAlign: 'middle' | 'top') => ({ id, header: '', cell: () => null, verticalAlign }); | ||
|
|
||
| render(<Table columnDefinitions={[def('1', 'middle')]} items={[]} />); | ||
|
|
||
| expect(useBaseComponentSpy).toHaveBeenCalledWith( | ||
| 'Table', | ||
| { | ||
| props: expect.objectContaining({ cellVerticalAlign: 'middle' }), | ||
| metadata: expect.objectContaining({ usesColumnDefinitionsVerticalAlign: false }), | ||
| }, | ||
| expect.anything() | ||
| ); | ||
|
|
||
| render(<Table columnDefinitions={[def('1', 'middle')]} items={[]} cellVerticalAlign="top" />); | ||
|
|
||
| expect(useBaseComponentSpy).toHaveBeenCalledWith( | ||
| 'Table', | ||
| { | ||
| props: expect.objectContaining({ cellVerticalAlign: 'top' }), | ||
| metadata: expect.objectContaining({ usesColumnDefinitionsVerticalAlign: true }), | ||
| }, | ||
| expect.anything() | ||
| ); | ||
|
|
||
| render(<Table columnDefinitions={[def('1', 'top'), def('2', 'top')]} items={[]} cellVerticalAlign="top" />); | ||
|
|
||
| expect(useBaseComponentSpy).toHaveBeenCalledWith( | ||
| 'Table', | ||
| { | ||
| props: expect.objectContaining({ cellVerticalAlign: 'top' }), | ||
| metadata: expect.objectContaining({ usesColumnDefinitionsVerticalAlign: false }), | ||
| }, | ||
| expect.anything() | ||
| ); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,14 @@ export interface TableProps<T = any> extends BaseComponentProps { | |
| * * `verticalAlign` ('middle' | 'top') - Determines the alignment of the content in the table cell. | ||
| */ | ||
| columnDefinitions: ReadonlyArray<TableProps.ColumnDefinition<T>>; | ||
|
|
||
| /** | ||
| * Determines the alignment of the content inside table cells. | ||
| * This property affects all cells, including the ones in the selection column. | ||
| * To target individual cells use `columnDefinitions.verticalAlign`, that takes precedence over `cellVerticalAlign`. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be a good idea to mention which one takes precedence here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's reasonable to assume but making it explicit and clear would be even better in my opinion. |
||
| cellVerticalAlign?: 'middle' | 'top'; | ||
|
|
||
| /** | ||
| * Specifies the selection type (`'single' | 'multi'`). | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.