Skip to content

Commit

Permalink
Merge pull request #782 from remap-keys/enable-scroll-in-keycode-list
Browse files Browse the repository at this point in the history
Enable scroll in the keycode list area.
  • Loading branch information
yoichiro authored Nov 29, 2023
2 parents 363b01a + a177a94 commit 05a9d18
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/configure/remap/Remap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
flex-direction: column;
padding: $space-m $space-m $space-xl $space-m;
background-color: $background-color-gray;
flex: 1;
overflow-y: auto;

.disable {
position: absolute;
Expand Down
44 changes: 43 additions & 1 deletion src/components/configure/remap/Remap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,55 @@ type OwnState = {
const MIN_SIDE_MENU_WIDTH = 80;

export default class Remap extends React.Component<RemapPropType, OwnState> {
private readonly keyboardWrapperRef: React.RefObject<HTMLDivElement>;
private readonly keycodeRef: React.RefObject<HTMLDivElement>;

constructor(props: RemapPropType | Readonly<RemapPropType>) {
super(props);
this.keyboardWrapperRef = React.createRef();
this.keycodeRef = React.createRef();
this.state = {
minWidth: 0,
};
}

private handleWindowResize() {
// To fetch the correct height of the keyboard wrapper,
// we need to wait until the keyboard wrapper is rendered.
setTimeout(() => {
if (!this.keyboardWrapperRef.current || !this.keycodeRef.current) {
return;
}
// Calculate the height of the keyboard wrapper,
// and set the height of the keycode wrapper
// to the height of the window minus the height of
// the keyboard wrapper dynamically.
const keyboardWrapperHeight =
this.keyboardWrapperRef.current.clientHeight;
const headerHeight = 56;
const footerHeight = 27;
const windowHeight = window.innerHeight;
const keycodeWrapperHeight =
windowHeight - keyboardWrapperHeight - headerHeight - footerHeight;
this.keycodeRef.current.style.height = `${keycodeWrapperHeight}px`;
}, 0);
}

componentDidMount() {
window.addEventListener('resize', this.handleWindowResize.bind(this));
}

componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize.bind(this));
}

componentDidUpdate(prevProps: RemapPropType) {
if (this.props.keyboardWidth != prevProps.keyboardWidth) {
this.setState({
minWidth: this.props.keyboardWidth! + MIN_SIDE_MENU_WIDTH * 2,
});
// Call once to set the initial height.
this.handleWindowResize();
}
}

Expand All @@ -42,10 +79,15 @@ export default class Remap extends React.Component<RemapPropType, OwnState> {
<div
className="keyboard-wrapper"
style={{ minWidth: this.state.minWidth }}
ref={this.keyboardWrapperRef}
>
<EditMode mode={this.props.macroKey ? 'macro' : 'keymap'} />
</div>
<div className="keycode" style={{ minWidth: this.state.minWidth }}>
<div
className="keycode"
style={{ minWidth: this.state.minWidth }}
ref={this.keycodeRef}
>
<Keycodes />
</div>
<Desc value={this.props.hoverKey} />
Expand Down

0 comments on commit 05a9d18

Please sign in to comment.