wojtekmaj / update-input-width Goto Github PK
View Code? Open in Web Editor NEWA function that given input element, updates its width to fit its content.
License: MIT License
A function that given input element, updates its width to fit its content.
License: MIT License
Hello, first of all thanks for the library - we're using it in a React project, however we are facing issues with rendering due to the following line:
update-input-width/src/index.js
Line 67 in ded6273
Updating the element like this makes the library not very React-friendly - DOM modifications should not be done on the element itself, but rather be relayed to the render method of each component.
A good addition to your lib would be splitting the logic inside updateInputWidth
into a separate getUpdatedInputWidth
and then allowing the consumer to set the width however they please (pass as props in the case of React).
Happy to do a PR if you think the request is reasonable.
Stacktrace:
at updateInputWidth (node_modules/update-input-width/dist/entry.js:22:16)
at ref (node_modules/react-date-picker/dist/DateInput/Input.js:73:42)
at commitAttachRef (node_modules/react-dom/cjs/react-dom.development.js:14456:7)
at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15467:7)
at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:100:14)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:138:16)
at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:187:29)
at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:15603:7)
at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:16618:34)
at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:16563:9)
at requestWork (node_modules/react-dom/cjs/react-dom.development.js:16347:7)
at scheduleWork$1 (node_modules/react-dom/cjs/react-dom.development.js:16218:11)
at scheduleRootUpdate (node_modules/react-dom/cjs/react-dom.development.js:16785:3)
at updateContainerAtExpirationTime (node_modules/react-dom/cjs/react-dom.development.js:16812:10)
at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:16839:10)
at ReactRoot.Object.<anonymous>.ReactRoot.render (node_modules/react-dom/cjs/react-dom.development.js:17122:3)
at node_modules/react-dom/cjs/react-dom.development.js:17262:14
at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:16674:14)
at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:17258:5)
at Object.render (node_modules/react-dom/cjs/react-dom.development.js:17317:12)
at node_modules/@testing-library/react/dist/index.js:86:25
at Object.batchedUpdates$1 [as unstable_batchedUpdates] (node_modules/react-dom/cjs/react-dom.development.js:16659:12)
at actPolyfill (node_modules/@testing-library/react/dist/act-compat.js:51:21)
at render (node_modules/@testing-library/react/dist/index.js:82:26)
at Object.<anonymous> (<RELEVANT_FILE_PATH>/tests/index.test.js:20:27)
Issue:
When running tests with the Jest framework the react-datetime-picker would break the tests with this error and stacktrace. Would not break during npm start, just broke during test.
Fix:
Dependencies:
"react-datetime-picker": "2.4.0",
Resolutions:
"resolutions": {
"react-datetime-picker/react-date-picker": "7.5.1",
"react-datetime-picker/react-time-picker": "3.5.2"
}
Reproduce:
Load http://projects.wojtekmaj.pl/react-date-picker/ in MS Edge.
Notice the end of each input is cut off.
This seems to be related to https://github.com/wojtekmaj/update-input-width not calculating the correct width in Edge.
With 7.8.1, rendering a DatePicker
in a react-responsive-modal
fails. Rendering inside the same modal after a delay works.
The error happens in line 20 of Input.jsx
wojtekmaj/react-date-picker@e0cc576 , and this might technically be a bug in getFontShorthand()
from update-input-width
.
It looks like this is because the modal's content is initially created outside of the document's DOM and document.getComputedStyle(element)
doesn't contain any font styles.
If the modal appears first and then displays the form after a delay (e.g. ajax loading), rendering works.
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.