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: add Platform#setTabindex() #293

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## unreleased changes
* `Platform#setTabindex()` を追加
* `InputHandler` の `view` の Element に `tabindex: 0` をデフォルトで付与するように
* これはバージョン 2.4.3 以前の挙動と同様となります。

## 2.8.0
* @akashic/[email protected] に追従
* `PointerEvent` サポート環境において `PointMoveEvent#button`, `PointUpEvent#button` に対応
Expand Down
4 changes: 4 additions & 0 deletions src/ContainerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class ContainerController {
}
}

setTabindex(index: number | undefined): void {
this.inputHandlerLayer.setViewTabindex(index);
}

private _loadView(): void {
const { primarySurfaceWidth: width, primarySurfaceHeight: height } = this._rendererReq;
// DocumentFragmentはinsertした時点で開放されているため毎回作る
Expand Down
6 changes: 6 additions & 0 deletions src/InputHandlerLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ export class InputHandlerLayer {
view.style.height = size.height + "px";
}

setViewTabindex(tabindex: number | undefined): void {
Copy link
Member

Choose a reason for hiding this comment

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

議論:

  • 利用者にとって、これを指定する引数は、後方互換性を考えると undefined をデフォルト値にせざるを得ない
  • tabindex の「デフォルト値」は "0" であるべきに思えるが、ここで undefined は「tabindexなし」の表現になっているので、辻褄が合わない
  • 考えられる選択肢:
    • (a) tabindex: number | "" のように明確に「tabindexなし」を表す表現を数値と undefined 以外に作る
    • (b) tabindex: string として全部文字列で受けてしまう
  • (b) は型的に過剰に広いが、 (a) はかなり見慣れない型付けになり、一長一短
  • ここでは (b) を採ることにする

const view = this.view;
view.setAttribute("tabindex", tabindex == null ? "" : tabindex.toString());
}

private _createInputView(width: number, height: number): HTMLDivElement {
const view = document.createElement("div");
view.setAttribute("style", "display:inline-block; outline:none;");
view.style.width = width + "px";
view.style.height = height + "px";
view.setAttribute("tabindex", "0");
return view;
}
}
4 changes: 4 additions & 0 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class Platform implements pdi.Platform {
return this._audioManager.getMasterVolume();
}

setTabindex(tabindex: number | undefined): void {
this.containerController.setTabindex(tabindex);
}

destroy(): void {
this.setRendererRequirement(undefined);
this.setMasterVolume(0);
Expand Down