Skip to content

Commit

Permalink
update react-auto-height library
Browse files Browse the repository at this point in the history
* remove workaround for window resize
* different workaround for details toggle
  • Loading branch information
Aprillion committed Jul 6, 2023
1 parent f966518 commit 2e8a011
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
23 changes: 0 additions & 23 deletions app/hooks/useRerenderOnResize.ts

This file was deleted.

14 changes: 5 additions & 9 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import {loadInitialQuestions, QuestionState} from '~/server-utils/stampy'
import {TOP} from '~/hooks/stateModifiers'
import useQuestionStateInUrl from '~/hooks/useQuestionStateInUrl'
import useRerenderOnResize from '~/hooks/useRerenderOnResize'
import useDraggable from '~/hooks/useDraggable'
import {getStateEntries} from '~/hooks/stateModifiers'
import Search from '~/components/search'
Expand Down Expand Up @@ -119,21 +118,21 @@ export default function App() {
glossary,
} = useQuestionStateInUrl(minLogo, initialQuestions)

useRerenderOnResize() // recalculate AutoHeight

const openQuestionTitles = questions
.filter(({questionState}) => questionState === '_')
.map(({title}) => title)

const showMore = (el: HTMLElement, toggle = false) => {
const container = el.closest('.react-auto-height') as HTMLElement
const button = container.getElementsByClassName('see-more')[0]
const container = el.closest<HTMLElement>('.react-auto-height')
const button = container?.getElementsByClassName('see-more')[0]
if (toggle) {
button?.classList.toggle('visible')
} else {
button?.classList.add('visible')
}
container.style.removeProperty('height')
// The AutoHeight component doesn't notice when a random <div> changes CSS class,
// so manually triggering toggle event (as if this was a <details> element).
dispatchEvent(new Event('toggle'))
}

const handleSpecialLinks = (e: MouseEvent) => {
Expand All @@ -145,9 +144,6 @@ export default function App() {
)
return

// The AutoHeight component doesn't notice when a HTML details is opened.
// Manually removing the height from the style fixes this, but can potentially
// break something else...
if (el.classList.contains('see-more')) {
showMore(el, true)
e.preventDefault()
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"markdown-it-footnote": "^3.0.3",
"node-html-parser": "^5.4.2",
"react": "^17.0.2",
"react-auto-height": "^1.1.6",
"react-auto-height": "^1.2.0",
"react-dom": "^17.0.2",
"remix": "^1.13.0"
},
Expand Down

0 comments on commit 2e8a011

Please sign in to comment.