-
Notifications
You must be signed in to change notification settings - Fork 156
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
fix: Prevent dragging options in Collection preferences from causing page overflow #1072
Changes from 9 commits
4f04088
644a72f
04ce1cf
85b0b4c
a39961d
72c4b95
0f94404
e4f716d
431a83d
75e18bd
b27ab27
7a609f5
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 |
---|---|---|
|
@@ -21,60 +21,54 @@ $border-radius: awsui.$border-radius-item; | |
} | ||
} | ||
|
||
.sortable-item-toggle { | ||
.content-display-option-toggle { | ||
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. Harmonized internal names with testing utils API: "sortable item" is now "content display option". |
||
/* used in test-utils */ | ||
} | ||
|
||
.sortable-item { | ||
position: relative; | ||
} | ||
|
||
.sortable-item-placeholder { | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
background: awsui.$color-drag-placeholder-hover; | ||
.content-display-option-content { | ||
@include styles.styles-reset; | ||
display: flex; | ||
align-items: flex-start; | ||
padding: awsui.$space-xs awsui.$space-scaled-xs awsui.$space-xs 0; | ||
background-color: awsui.$color-background-container-content; | ||
border-radius: $border-radius; | ||
} | ||
|
||
.sortable-item-content { | ||
.content-display-option { | ||
list-style: none; | ||
position: relative; | ||
border-top: awsui.$border-divider-list-width solid awsui.$color-border-divider-default; | ||
display: flex; | ||
flex-wrap: nowrap; | ||
justify-content: space-between; | ||
align-items: flex-start; | ||
padding-top: awsui.$space-xs; | ||
padding-bottom: awsui.$space-xs; | ||
padding-right: 0; | ||
&:not(.draggable) { | ||
padding-left: awsui.$space-scaled-l; | ||
} | ||
&.draggable { | ||
padding-left: 0; | ||
padding-right: awsui.$space-scaled-xs; | ||
background-color: awsui.$color-background-container-content; | ||
&:not(.placeholder).sorting { | ||
@include animated; | ||
z-index: 1; | ||
&.active { | ||
} | ||
&.placeholder { | ||
> .content-display-option-content { | ||
position: relative; | ||
z-index: 2; | ||
box-shadow: awsui.$shadow-container-active; | ||
border-radius: $border-radius; | ||
} | ||
&:not(.active).sorting { | ||
@include animated; | ||
} | ||
@include focus-visible { | ||
&.active { | ||
@include animated; | ||
@include styles.focus-highlight(0px); | ||
&:after { | ||
content: ' '; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
background: awsui.$color-drag-placeholder-hover; | ||
border-radius: $border-radius; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.sortable-item-label { | ||
padding-right: awsui.$space-l; | ||
.content-display-option-label { | ||
flex-grow: 1; | ||
overflow: hidden; | ||
padding-right: awsui.$space-l; | ||
} | ||
|
||
.drag-overlay { | ||
box-shadow: awsui.$shadow-container-active; | ||
border-radius: $border-radius; | ||
@include focus-visible { | ||
@include styles.focus-highlight(0px, $border-radius); | ||
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. The second parameter |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import styles from '../styles.css.js'; | ||
import DragHandle from '../../internal/drag-handle'; | ||
import InternalToggle from '../../toggle/internal'; | ||
import React, { ForwardedRef, forwardRef } from 'react'; | ||
import { SyntheticListenerMap } from '@dnd-kit/core/dist/hooks/utilities'; | ||
import { OptionWithVisibility } from './utils'; | ||
import { useUniqueId } from '../../internal/hooks/use-unique-id'; | ||
|
||
const componentPrefix = 'content-display-option'; | ||
export const getClassName = (suffix?: string) => styles[[componentPrefix, suffix].filter(Boolean).join('-')]; | ||
|
||
export interface ContentDisplayItemProps { | ||
dragHandleAriaLabel?: string; | ||
listeners?: SyntheticListenerMap; | ||
onToggle?: (option: OptionWithVisibility) => void; | ||
option: OptionWithVisibility; | ||
} | ||
|
||
const ContentDisplayOption = forwardRef( | ||
( | ||
{ dragHandleAriaLabel, listeners, onToggle, option }: ContentDisplayItemProps, | ||
ref: ForwardedRef<HTMLDivElement> | ||
) => { | ||
const idPrefix = useUniqueId(componentPrefix); | ||
const controlId = `${idPrefix}-control-${option.id}`; | ||
|
||
const dragHandleAttributes = { | ||
['aria-label']: [dragHandleAriaLabel, option.label].join(', '), | ||
}; | ||
|
||
return ( | ||
<div ref={ref} className={getClassName('content')}> | ||
<DragHandle attributes={dragHandleAttributes} listeners={listeners} /> | ||
|
||
<label className={getClassName('label')} htmlFor={controlId}> | ||
{option.label} | ||
</label> | ||
<div className={getClassName('toggle')}> | ||
<InternalToggle | ||
checked={!!option.visible} | ||
onChange={() => onToggle && onToggle(option)} | ||
disabled={option.alwaysVisible === true} | ||
controlId={controlId} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default ContentDisplayOption; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
import { useSortable } from '@dnd-kit/sortable'; | ||
import { CSS } from '@dnd-kit/utilities'; | ||
import { OptionWithVisibility } from './utils'; | ||
import ContentDisplayOption, { getClassName } from './content-display-option'; | ||
import clsx from 'clsx'; | ||
import styles from '../styles.css.js'; | ||
|
||
export default function DraggableOption({ | ||
dragHandleAriaLabel, | ||
onKeyDown, | ||
onToggle, | ||
option, | ||
}: { | ||
dragHandleAriaLabel?: string; | ||
onKeyDown?: (event: React.KeyboardEvent) => void; | ||
onToggle: (option: OptionWithVisibility) => void; | ||
option: OptionWithVisibility; | ||
}) { | ||
const { isDragging, isSorting, listeners, setNodeRef, transform } = useSortable({ | ||
id: option.id, | ||
}); | ||
const style = { | ||
transform: CSS.Translate.toString(transform), | ||
}; | ||
|
||
const combinedListeners = { | ||
...listeners, | ||
onKeyDown: (event: React.KeyboardEvent) => { | ||
if (onKeyDown) { | ||
onKeyDown(event); | ||
} | ||
if (listeners?.onKeyDown) { | ||
listeners.onKeyDown(event); | ||
} | ||
}, | ||
}; | ||
|
||
return ( | ||
<li className={clsx(getClassName(), isDragging && styles.placeholder, isSorting && styles.sorting)} style={style}> | ||
<ContentDisplayOption | ||
ref={setNodeRef} | ||
listeners={combinedListeners} | ||
dragHandleAriaLabel={dragHandleAriaLabel} | ||
onToggle={onToggle} | ||
option={option} | ||
/> | ||
</li> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
page.pause()
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done