Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ export function useOverflow ({ containerRef, truncated = false }) {
const router = useRouter()
// would the text overflow on the current screen size?
const [overflowing, setOverflowing] = useState(false)
// should we show the full text?
const [show, setShow] = useState(false)
const showOverflow = useCallback(() => setShow(true), [setShow])
// always show the full text if the `full` query param is set
const [show, setShow] = useState(!!router.query.full)
Comment thread
Soxasora marked this conversation as resolved.
Outdated

const showOverflow = useCallback(() => {
// save the full text state to the query param
router.replace({
pathname: router.pathname,
query: { ...router.query, full: true }
}, router.asPath, { shallow: true })
setShow(true)
}, [router])

// if we are navigating to a hash, show the full text
useEffect(() => {
setShow(router.asPath.includes('#'))
const handleRouteChange = (url, { shallow }) => {
setShow(url.includes('#'))
if (router.asPath.includes('#')) setShow(true)
const handleRouteChange = (url) => {
if (url.includes('#')) setShow(true)
Comment thread
Soxasora marked this conversation as resolved.
Outdated
}

router.events.on('hashChangeStart', handleRouteChange)
Expand Down
Loading