ferdaber / react-focus-within Goto Github PK
View Code? Open in Web Editor NEWFocus-within behavior in React
Focus-within behavior in React
Why does react-focus-within add a event listener on my dom? After using this whenever I am clicking anywhere this onDocumentMouseUp
keeps calling.
This library is exactly what I need for a project. However, I can't get it to work at all for some reason. I have a very simple test script, which seems to just ignore the <button> focus completely:
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import FocusWithin from 'react-focus-within'
class Test extends React.Component {
render() {
return <FocusWithin onFocus={() => console.log('focus pocus')}>{({ isFocused }) => (
<button className={isFocused?'bg-success':'bg-primary'}>Go</button>
)}</FocusWithin>
}
}
ReactDOM.render(<Test/>, document.getElementById('app'))
I'm using react 16.8.5 and react-focus-within 2.0.1. Help would be greatly appreciated!
When using FocusWithin
, TS throws the following error:
TS2339: Property 'focusProps' does not exist on type 'FocusWithinRenderProps'.
It's happening because focusProps
is missing in
export interface FocusWithinRenderProps {
getFocusProps<P>(
props?: P
): {
onFocus(event: object): void
onBlur(event: object): void
onMouseDown(event: object): void
} & P
isFocused: boolean
}
When running npm i
when react-focus-within is a dependency, this error occurs and installation stops:
PS C:\Users\alexa\apf2> npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/react-focus-within
npm ERR! react-focus-within@"2.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
This forces to use npm i --force
which is not recommended.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.