Код: Выделить всё
// some style wrapper:
const InstructionBox = styled(Box)(() => ({
display: '-webkit-box',
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
lineClamp: 3,
WebkitLineClamp: 3
}));
// use effect that determines whether there are more lines than the clamp:
useEffect(() => {
if (instructionBoxTextRef.current) {
const { current } = instructionBoxTextRef;
if (current.scrollHeight > current.offsetHeight) {
setShowMore(true);
}
}
}, [instructionBoxTextRef]);
// the representative box around variable instruction data:
// and the little button jsx:
{showMore && (
Show More
)}
< /code>
Это работает визуально просто идеально. Открытый переключатель работает очень хорошо, чтобы открыть модал, когда существует более трех строк текста инструкции, показывая полные инструкции в модале. Я пробовал:
Подробнее здесь: https://stackoverflow.com/questions/794 ... ore-button
Мобильная версия