Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: truncated text when width is auto #1673

Merged
merged 4 commits into from May 20, 2022
Merged

Conversation

jajugoguma
Copy link
Contributor

Please check if the PR fulfills these requirements

  • It's submitted to right branch according to our branching model
  • It's right issue type on title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has description for the breaking change

Description

  • Fixed the text being cut off when the width is auto.
    • Fixed to get the actual width after adding an element with text to the DOM.

As-Is

스크린샷 2022-05-16 18 06 28

To-Be

스크린샷 2022-05-16 18 07 14


Thank you for your contribution to TOAST UI product. 🎉 😘 ✨

Copy link
Member

@dotaitch dotaitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료합니다~ 리뷰 남긴게 있는데 이건 이미 처리됐네요ㅎㅎ;; 참고차 리뷰는 안지우고 그대로 올릴게요!

const context = document.createElement('canvas').getContext('2d')!;
context.font = font;
const { width } = context.measureText(String(text));
export function getTextWidth(text: string, font?: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

font 인자값이 쓰이지 않네요. 추후 개발을 위해 font를 나두어야 한다면 아래 eslint 룰을 적용해도 좋을 것 같아요. 참고로 TOAST UI Calendar에도 적용되어 있습니다.

https://eslint.org/docs/rules/no-unused-vars#argsignorepattern

Copy link

@adhrinae adhrinae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

늦게나마 리뷰 완료합니다. 디스패치에서 DOM 헬퍼를 직접 가져다 써야하는게 좀 아쉽긴한데 제대로 사이즈 재려면 어쩔수 없긴 하죠.

Comment on lines 320 to 322
const bodyArea = document.querySelector(
`.${cls('rside-area')} .${cls('body-container')} .${cls('table')}`
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bodyArea 를 인자로 받게 할 수는 없을까요? 인자를 넘기는게 코드가 좀 복잡해보이긴 하지만, 디스패치에서 이 함수를 루프에서 직접 호출하는게 너무 큰 사이드 이펙트라고 느껴져서요. 어차피 그리드가 마운트되고 나면 이 엘리먼트는 어디로 사라지는 것도 아니니까 reduce 루프의 상위 스코프에서 한 번만 찾고 인자로 전달하는 식으로 했음 좋겠네요.

Copy link

@lja1018 lja1018 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료합니다.

Comment on lines 447 to 449
return texts.reduce((acc, text) => {
return text.length > acc.length ? text : acc;
}, '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return texts.reduce((acc, text) => {
return text.length > acc.length ? text : acc;
}, '');
return texts.reduce((acc, text) => text.length > acc.length ? text : acc, '');

바로 리턴할 수 있을 것 같아요.

@jajugoguma jajugoguma merged commit 6b9c4e4 into master May 20, 2022
@jajugoguma jajugoguma deleted the fix/truncated-text branch May 20, 2022 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants