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

feat: focusOptions changes, replaced focusName - with field and index, added focusOptions to all array methods #103

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

TheKucel
Copy link
Collaborator

@TheKucel TheKucel commented Aug 20, 2024

Поменял focusOptions, убрал focusName, и добавил field и index как 2 отдельных поля
Так же добавил focusOptions для каждого метода массива, и установил дефолтные индексы при передаче field
(Дефолтный индекс срабатывает если передаём название поля, но не передаём индекс)

Дефолтный индекс указывал по следующему принципу - "то что последнее изменили"

  1. append - фокус на добавленное (последнее) поле
  2. insert - фокус на добавленное (указанное) поле
  3. move - фокус на перемещённое (to) поле
  4. swap - фокус на перемещённое (to) поле
  5. remove - фокус на предыдущее (если нет предыдущего то на первое) поле

+Покрыл это тестами

@@ -110,13 +110,11 @@ export default {

this.fieldComponents.splice(index, 1);
},
handleFocus({ focusName }) {
handleFocus({ field, index }) {
Copy link
Owner

Choose a reason for hiding this comment

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

Может тут тогда индекс по умолчанию присваивать в 0? Всё равно ниже это и делаешь :)

Copy link
Owner

Choose a reason for hiding this comment

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

Возможно стоит бросать исключение, если не передан field, иначе не понятно что фокусировать :) Что думаешь?

Copy link
Collaborator Author

@TheKucel TheKucel Aug 27, 2024

Choose a reason for hiding this comment

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

Угу, добавил ошибку если field не передан, возможно нужно указать явно undefined, но вроде как name не может быть пустой строкой по этому закинул более простую проверку

дефолтное значение на index тоже закинул


if (focusOptions && this.fields.length) {
// by default focus on previous field, if there is no previous field focus on first field
this.handleFocus({ index: index - 1 || 0, ...focusOptions });
Copy link
Owner

Choose a reason for hiding this comment

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

Если index будет 0, то у тебя фокусировать будет -1 элемент :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

И вправду проглядел :) Спасибо! поправил

Boris Andreiko added 2 commits August 27, 2024 14:53
Copy link
Owner

@leonied7 leonied7 left a comment

Choose a reason for hiding this comment

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

Чётко!

@TheKucel TheKucel merged commit 1c1382e into v2 Aug 29, 2024
3 checks passed
@TheKucel TheKucel deleted the v2-change-focus-options branch August 29, 2024 11:30
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.

2 participants