Skip to content

Commit

Permalink
Replace defaultProps with default function parameters
Browse files Browse the repository at this point in the history
As default props on function components are going to be deprecated in future release in favor of default function parameters (see: facebook/react#16210), I followed the recommendation. Note that default function parameters were actually already used (see `lockProps` for example)!
  • Loading branch information
wojtekmaj committed Oct 11, 2023
1 parent 5b6a523 commit e3a436b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 44 deletions.
8 changes: 2 additions & 6 deletions src/FocusGuard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ export const hiddenGuard = {
left: '1px',
};

const InFocusGuard = ({ children }) => (
const InFocusGuard = ({ children = null }) => (
<React.Fragment>
<div key="guard-first" data-focus-guard data-focus-auto-guard style={hiddenGuard} />
{children}
{children && <div key="guard-last" data-focus-guard data-focus-auto-guard style={hiddenGuard} />}
</React.Fragment>
);

InFocusGuard.propTypes = {
children: PropTypes.node,
};

InFocusGuard.defaultProps = {
children: null,
};


export default InFocusGuard;
4 changes: 0 additions & 4 deletions src/FreeFocusInside.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ FreeFocusInside.propTypes = {
className: PropTypes.string,
};

FreeFocusInside.defaultProps = {
className: undefined,
};

export default FreeFocusInside;
34 changes: 6 additions & 28 deletions src/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const FocusLock = React.forwardRef(function FocusLockUI(props, parentRef) {

const {
children,
disabled,
noFocusGuards,
persistentFocus,
crossFrame,
autoFocus,
disabled = false,
noFocusGuards = false,
persistentFocus = false,
crossFrame = true,
autoFocus = true,
allowTextSelection,
group,
className,
Expand All @@ -34,7 +34,7 @@ const FocusLock = React.forwardRef(function FocusLockUI(props, parentRef) {
lockProps: containerProps = {},
sideCar: SideCar,

returnFocus: shouldReturnFocus,
returnFocus: shouldReturnFocus = false,
focusOptions,

onActivation: onActivationCallback,
Expand Down Expand Up @@ -208,26 +208,4 @@ FocusLock.propTypes = {
sideCar: any.isRequired,
};

FocusLock.defaultProps = {
children: undefined,
disabled: false,
returnFocus: false,
focusOptions: undefined,
noFocusGuards: false,
autoFocus: true,
persistentFocus: false,
crossFrame: true,
hasPositiveIndices: undefined,
allowTextSelection: undefined,
group: undefined,
className: undefined,
whiteList: undefined,
shards: undefined,
as: 'div',
lockProps: {},

onActivation: undefined,
onDeactivation: undefined,
};

export default FocusLock;
7 changes: 1 addition & 6 deletions src/MoveFocusInside.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useFocusInside = (observedRef) => {
}, [observedRef]);
};

function MoveFocusInside({ disabled: isDisabled, className, children }) {
function MoveFocusInside({ disabled: isDisabled = false, className, children }) {
const ref = React.useRef(null);
useFocusInside(isDisabled ? undefined : ref);

Expand All @@ -42,9 +42,4 @@ MoveFocusInside.propTypes = {
className: PropTypes.string,
};

MoveFocusInside.defaultProps = {
disabled: false,
className: undefined,
};

export default MoveFocusInside;

0 comments on commit e3a436b

Please sign in to comment.