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

FocalPointPicker: Fix rendering and dragging experience #28096

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/components/src/focal-point-picker/focal-point.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import {
PointerIconSVG,
FocalPointWrapper,
PointerIconPathFill,
PointerIconPathOutline,
FocalPointWrapper,
PointerIconSVG,
} from './styles/focal-point-style';

/**
* External dependencies
*/
import classnames from 'classnames';

export default function FocalPoint( {
coordinates = { left: '50%', top: '50%' },
isDragging = false,
...props
} ) {
const classes = classnames(
'components-focal-point-picker__icon_container',
isDragging && 'is-dragging'
'components-focal-point-picker__icon_container'
);

const style = {
Expand Down
13 changes: 12 additions & 1 deletion packages/components/src/focal-point-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ export class FocalPointPicker extends Component {
componentDidMount() {
document.addEventListener( 'mouseup', this.handleOnMouseUp );
window.addEventListener( 'resize', this.updateBounds );

/*
* Set initial bound values.
*
* This is necessary for Safari:
* https://github.com/WordPress/gutenberg/issues/25814
*/
this.updateBounds();
}
componentDidUpdate( prevProps ) {
if ( prevProps.url !== this.props.url ) {
this.setState( {
isDragging: false,
} );
}
/**
/*
* Handles cases where the incoming value changes.
* An example is the values resetting based on an UNDO action.
*/
Expand Down Expand Up @@ -173,6 +181,9 @@ export class FocalPointPicker extends Component {

if ( ! isDragging ) return;

// Prevents text-selection when dragging.
event.preventDefault();

const { shiftKey } = event;
const pickerDimensions = this.pickerDimensions();
const cursorPosition = {
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/input-control/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ export function useDragCursor( isDragging, dragDirection ) {
useEffect( () => {
if ( isDragging ) {
document.documentElement.style.cursor = dragCursor;
document.documentElement.style.pointerEvents = 'none';
} else {
document.documentElement.style.cursor = null;
document.documentElement.style.pointerEvents = null;
}
}, [ isDragging ] );

Expand Down