Skip to content

Commit

Permalink
Data views: set initial selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 9, 2024
1 parent 8e93e79 commit f62709a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataViews } from '@wordpress/dataviews';
import { __ } from '@wordpress/i18n';
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { getTitleFromBlocks } from './read-write';

function Title({ item: { path, blocks } }) {
Expand Down Expand Up @@ -31,6 +31,17 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
);
}

// Temporary hack until we can control selection in data views.
useEffect(() => {
const button = document.getElementById('view-list-0-' + currentId);

if (button?.getAttribute('aria-pressed') === 'false') {
const { activeElement } = document;
button.click();
activeElement.focus();
}
}, [currentId]);

return (
<DataViews
data={items}
Expand Down
1 change: 1 addition & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ ul.dataviews-view-list li {
#select .components-toolbar {
border-color: #e0e0e0;
border-width: 0 1px 0 0;
background-color: transparent;
}

#editor > div {
Expand Down

0 comments on commit f62709a

Please sign in to comment.