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

Simplify aria table resizing docs example #4253

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented Mar 23, 2023

Based on #3982.

This is a slightly simpler implementation of the column resizing example that doesn't require overriding the CSS table layout to use flex. This way we can simply reuse the TableRowGroup, TableHeaderRow, TableRow, and TableCell components from before instead of reimplementing them with minor styling changes.

It works by adding an additional div wrapper around the table element that scrolls. The table itself is set to width: fit-content and table-layout: fixed to ensure it always takes the widths defined on the column headers. Then the browser automatically handles setting the widths of the cells in the body based on the header widths, and the entire table grows when the widths get bigger (overflowing in the parent wrapper).

You do lose the sticky headers, but in this example there is no vertical scrolling anyway so I'd rather keep the example simpler to focus on the concepts related to resizing itself. The styled example goes into more detail there as well.

Edit: sticky headers can actually be achieved as well. If you add position: sticky; top: 0 to the tr element in the header and a max-height on the wrapper div it does stick as expected. But anyway it wouldn't be shown in the example because it doesn't vertically scroll.

@devongovett devongovett mentioned this pull request Mar 23, 2023
5 tasks
@rspbot
Copy link

rspbot commented Mar 23, 2023

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Just one small nit, I'll push an update

packages/@react-aria/table/docs/useTable.mdx Outdated Show resolved Hide resolved
@rspbot
Copy link

rspbot commented Mar 23, 2023

@rspbot
Copy link

rspbot commented Mar 23, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set
undefined already in set

@react-aria/dnd

isVirtualDragging

-isDirectoryDropItem {
-  dropItem: DropItem
-  returnVal: undefined
-}
+

isDirectoryDropItem

-isFileDropItem {
-  dropItem: DropItem
-  returnVal: undefined
-}
+

isFileDropItem

-isTextDropItem {
-  dropItem: DropItem
-  returnVal: undefined
-}
+

@react-aria/interactions

useFocus

changed by:

  • FocusProps
  • FocusResult
-useFocus<Target = FocusableElement> {
-  props: FocusProps<Target>
-  returnVal: undefined
-}
+

FocusProps

-FocusProps<Target = FocusableElement> {
-  isDisabled?: boolean
-}
+

it changed:

  • useFocus

FocusResult

-FocusResult<Target = FocusableElement> {
-  focusProps: DOMAttributes<Target>
-}
+

it changed:

  • useFocus

undefined

-
+useFocus {
+  props: FocusProps
+  returnVal: undefined
+}

undefined

-
+FocusProps {
+  isDisabled?: boolean
+}

undefined

-
+FocusResult {
+  focusProps: DOMAttributes
+}

@react-aria/tabs

useTabList

changed by:

  • AriaTabListOptions
 useTabList<T> {
-  props: AriaTabListOptions<T>
+  props: AriaTabListProps<T>
   state: TabListState<T>
   ref: RefObject<HTMLElement>
   returnVal: undefined
 }

AriaTabListOptions

-AriaTabListOptions<T> {
 
-}

it changed:

  • useTabList

@react-aria/utils

mergeProps

-mergeProps<T extends Array<PropsArg>> {
-  args: T
-  returnVal: undefined
-}
+

isVirtualPointerEvent

-
+mergeProps<T extends Array<Props>> {
+  args: T
+  returnVal: undefined
+}

@react-stately/calendar

useCalendarState

changed by:

  • CalendarStateOptions
-useCalendarState<T extends DateValue = DateValue> {
-  props: CalendarStateOptions<T>
-  returnVal: undefined
-}
+

useRangeCalendarState

changed by:

  • RangeCalendarStateOptions
-useRangeCalendarState<T extends DateValue = DateValue> {
-  props: RangeCalendarStateOptions<T>
-  returnVal: undefined
-}
+

CalendarStateOptions

-CalendarStateOptions<T extends DateValue = DateValue> {
-  createCalendar: (string) => Calendar
-  locale: string
-  selectionAlignment?: 'start' | 'center' | 'end'
-  visibleDuration?: DateDuration = {months: 1}
-}
+

it changed:

  • useCalendarState

RangeCalendarStateOptions

-RangeCalendarStateOptions<T extends DateValue = DateValue> {
-  createCalendar: (string) => Calendar
-  locale: string
-  visibleDuration?: DateDuration = {months: 1}
-}
+

it changed:

  • useRangeCalendarState

undefined

-
+useCalendarState {
+  props: CalendarStateOptions
+  returnVal: undefined
+}

undefined

-
+useRangeCalendarState {
+  props: RangeCalendarStateOptions
+  returnVal: undefined
+}

undefined

-
+CalendarStateOptions {
+  createCalendar: (string) => Calendar
+  locale: string
+  selectionAlignment?: 'start' | 'center' | 'end'
+  visibleDuration?: DateDuration = {months: 1}
+}

undefined

-
+RangeCalendarStateOptions {
+  createCalendar: (string) => Calendar
+  locale: string
+  visibleDuration?: DateDuration = {months: 1}
+}

@react-stately/datepicker

useDateFieldState

changed by:

  • DateFieldStateOptions
-useDateFieldState<T extends DateValue = DateValue> {
-  props: DateFieldStateOptions<T>
-  returnVal: undefined
-}
+

useDateRangePickerState

changed by:

  • DateRangePickerStateOptions
-useDateRangePickerState<T extends DateValue = DateValue> {
-  props: DateRangePickerStateOptions<T>
-  returnVal: undefined
-}
+

useTimeFieldState

changed by:

  • TimeFieldStateOptions
-useTimeFieldState<T extends TimeValue = TimeValue> {
-  props: TimeFieldStateOptions<T>
-  returnVal: undefined
-}
+

DateFieldStateOptions

-DateFieldStateOptions<T extends DateValue = DateValue> {
-  createCalendar: (string) => Calendar
-  locale: string
-  maxGranularity?: 'year' | 'month' | Granularity = 'year'
-}
+

it changed:

  • useDateFieldState

DateRangePickerStateOptions

-DateRangePickerStateOptions<T extends DateValue = DateValue> {
-  shouldCloseOnSelect?: boolean | () => boolean = true
-}
+

it changed:

  • useDateRangePickerState

TimeFieldStateOptions

-TimeFieldStateOptions<T extends TimeValue = TimeValue> {
-  locale: string
-}
+

it changed:

  • useTimeFieldState

undefined

-
+useDateFieldState {
+  props: DateFieldStateOptions
+  returnVal: undefined
+}

undefined

-
+useDateRangePickerState {
+  props: DateRangePickerStateOptions
+  returnVal: undefined
+}

undefined

-
+useTimeFieldState {
+  props: TimeFieldStateOptions
+  returnVal: undefined
+}

undefined

-
+DateFieldStateOptions {
+  createCalendar: (string) => Calendar
+  locale: string
+  maxGranularity?: 'year' | 'month' | Granularity = 'year'
+}

undefined

-
+DateRangePickerStateOptions {
+  shouldCloseOnSelect?: boolean | () => boolean = true
+}

undefined

-
+TimeFieldStateOptions {
+  locale: string
+}

@devongovett
Copy link
Member Author

Oh hmm I was wondering why it was so small. Kinda annoying on large screens but oh well

@devongovett devongovett merged commit 6c17a72 into aria_table_docs Mar 23, 2023
@devongovett devongovett deleted the aria-resizing-docs-simplify branch March 23, 2023 22:39
LFDanLu added a commit that referenced this pull request Apr 5, 2023
* progress for making aria table resizing example

* styling updates and addition of menu button for resizing

* fixing it so user doesnt focus the resizer immediately when using left/right arrows

still a bit iffy, cant seem to get focus to move between the columns, def something with the menutrigger...

* making column resize actually get called if provided

* fixing bugs, testing various cases, adding description to useTableColumnResizeState

* Fix crash if onColumnResize is undef

* figure out break

* fix docs build break, add rest of code

* fix docs example render issues

* remove onColumnResize/Start/End from useTableColumnResizeState

these are unecessary since the state returns the resizing column already and we have onResize handlers in useTableColumnResize

* docs first draft

* remove local test story for now

* small cleanup

* updating resizer in docs

* fixing talkback and Safari aria resizer focus issues

* fixing checkbox rendering in iOS Safari

* editing/proofreading

* move useTableColumnResizeState to useTableState docs

* moving resizable table section and addressing smaller changes

* simplifying example

* collapsing some parts of the code and trying to display the code blocks as is

* addressing review comments

* add tailwind example

* forgot to add some additional comments

* override native focus ring for button

* update copy as per review and re-collapse code blocks

collapsed code blocks feel better on mobile so I changed it back to that

* uncollapsing code blocks

* Rough example of press header to start resizing

* Updating column resize to support mode where resizer is always visible

split out from #4061, see that PR for more details and alternative approaches

* update to match latest changes to api

* mimic docs example

* forgot to clean up some things

* pulling in code changes from docs PR

get rid of inline styles and fix case where there isnt a separate trigger for starting column resize

* Add separate mode for triggering resizing manually via Enter (#4061)

* adding separate mode for enabling resize

this make it so the user would have to hit Enter to start resizing. This allows us to have the resizers always be visible and still preserve grid navigation between columns.

* skip test for now so build works for testing

* wrap useMove so it doesnt trigger keyboard handlers when edit mode isnt enabled

* update tableview so that it enters edit mode when choosing to resize via menu

still one bug where manager.isFocused is set to false for somereason after confirming the resize

* fixing bugs

fixes bug where selection manager would stop tracking if the manager is focused or not if keyboard nav was disabled. This was a bug where the user wouldnt be able to move table focus after confirming a resize operation. Adds new prop to useTableColumnResize for triggering resizeStart if resizer if focused. This is needed for our table since we dont have a way to call resizeStart programmatically out side of useTableColumnResize and we dont want to call it on focus for the aria example since that should require a manual trigger of Enter to enter resize mode

* updating description and missing logic

* getting rid of shouldResizeOnFocus prop

* fix skipped test

turns out the simulated resize operation was blurring before pressEnd finished

* updated docs to move inline css into classnames

also updates copy and handles case where trigger ref isnt provided

* remove sorting story and cleanup

* starting resize on press for indicator

this unfortunately causes a difference in behavior between starting a drag on menu (no resizestart until move) and starting a drag via mouse/touch (resizestart immediately on press)

* using triggerRef existance to determine if behavior is resize on focus

one test is still breaking, debugging

* fixing test

test would blur on rerender causing a column width update even though resizing wasnt happening. Changed conditonal so calling endResize only causes value updates if we are resizing

* make resizer single line for focus

* nit reorganizing

* update docs example for resizer styling

* mimic docs example

remove selection from example to mirror docs

* adding description for keyboard users for Enter to start resizing

this is for the aria table example where resizing is entered manually via Enter while focused on the resizer

* fixing issue where tab wasnt exiting the table when focused on the reizer

* adding min width for columns to avoid weirdness with trying to collapse 0

* fix lint

* avoid weirdness with width 0 by setting a min width

* propagate all keydown events if we arent in resize mode and have always visible resizers

forgot that we also have other keyboard combos like cmd + a or escape that should also be handled by useSelectableCollection

* removing ref read in render

* add aria description to input for virtual modality too

if the user enters the table using control+option+arrow keys in voiceover, they will be virtual modality so we want the description for press enter to resize to be audible there

* addressing review comments

* fix some copy

* prevent extraneous scrolling when keyboard navigating to the resizer

margin applied on the visually hidden input makes scrollIntoView think it needs to scroll it

* fixing extraneous scrolling behavior

* address review comments

* fix logic

* removing margin style in favor of hook provided style

* fix typescript lint

* make resize handle larger

* fix resizer style on drag

* Simplify aria table resizing docs example (#4253)

* update example to match updated hooks

* remove VisuallyHidden from resizer in favor of styles from hook

* adding version badge

---------

Co-authored-by: Robert Snow <rsnow@adobe.com>
Co-authored-by: Devon Govett <devongovett@gmail.com>
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.

4 participants