Skip to content

Commit

Permalink
Fix isDisabled so that it keeps its value even if it is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Aug 20, 2022
1 parent 7909220 commit 28820f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions packages/components/src/disabled/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -12,9 +7,10 @@ import { createContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import { StyledWrapper } from './styles/disabled-styles';
import { disabledStyles } from './styles/disabled-styles';
import type { DisabledProps } from './types';
import type { WordPressComponentProps } from '../ui/context';
import { useCx } from '../utils';

const Context = createContext< boolean >( false );
const { Consumer, Provider } = Context;
Expand Down Expand Up @@ -56,20 +52,28 @@ function Disabled( {
...props
}: Omit< WordPressComponentProps< DisabledProps, 'div' >, 'ref' > ) {
const ref = useDisabled();

const cx = useCx();
if ( ! isDisabled ) {
return <Provider value={ false }>{ children }</Provider>;
return (
<Provider value={ false }>
<div>{ children }</div>

This comment has been minimized.

Copy link
@torounit

torounit Aug 20, 2022

Author Member

For now, ...props is not added.

</Provider>
);
}

return (
<Provider value={ true }>
<StyledWrapper
<div
ref={ ref }
className={ classnames( className, 'components-disabled' ) }
className={ cx(
disabledStyles,
className,
'components-disabled'
) }
{ ...props }
>
{ children }
</StyledWrapper>
</div>
</Provider>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/disabled/styles/disabled-styles.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* External dependencies
*/
import styled from '@emotion/styled';
import { css } from '@emotion/react';

export const StyledWrapper = styled.div`
export const disabledStyles = css`
position: relative;
pointer-events: none;
Expand Down

0 comments on commit 28820f0

Please sign in to comment.